Closed ryan-williams closed 5 months ago
This appears to be caused by typing.is_typeddict()
not recognizing typing_extensions.TypedDict
. I'll follow up with a fix.
ty!
FWIW, in my actual codebase, I worked around this by moving from typing_extensions.TypedDict
to typing.TypedDict
, which is possible in Python ≥3.8.
Whatever's happening here seems pretty niche, but appreciate your looking into it!
Hm, I'm having trouble reproducing the problem on Python 3.11 and latest typing_extensions. Just to be sure, could you convert that into a standalone script that repros the issue?
It should be standalone here in my repro repo.
Here's the failure in a simple Github Action. Just above you can see pip list
:
Package Version Editable project location
---------------------- ------- ---------------------------------------------------
attrs 23.2.0
iniconfig 2.0.0
packaging 24.0
pip 24.0
pluggy 1.4.0
pytest 8.1.1
setuptools 65.5.0
typeguard 4.1.5
typeguard-callable-bug 0.0.0 /home/runner/work/typeguard-issues/typeguard-issues
typing_extensions 4.10.0
Seems to be on latest typing_extensions, 4.10.0.
Here's a Dockerfile:
FROM python:3.11.8
RUN git clone https://github.com/ryan-williams/typeguard-issues
WORKDIR typeguard-issues
RUN pip install -e .
RUN pytest src/test_typeddict.py # ❌ TypeError: TypedDict does not support instance and class checks
Thanks, I'll test it shortly.
Ok, I managed to repro it without Docker or pytest. I have a fix in place, just need to write a test.
Things to check first
[X] I have searched the existing issues and didn't find my bug already reported there
[X] I have checked that my bug is still present in the latest release
Typeguard version
4.1.5
Python version
3.11.8
What happened?
See test_typeddict.py:
test_typeddict
below fails, as written, with errorTypeError: TypedDict does not support instance and class checks
.typing.TypedDict
is used (instead oftyping_extensions.TypedDict
)typeguard_ignore
is imported directly:from typeguard import typeguard_ignore
How can we reproduce the bug?
ryan-williams/typeguard-issues has a working repro; here's the error in Github Actions.