agronholm / typeguard

Run-time type checker for Python
Other
1.55k stars 114 forks source link

"TypedDict does not support instance and class checks" with Python 3.13 #453

Closed musicinmybrain closed 6 months ago

musicinmybrain commented 7 months ago

Things to check first

Typeguard version

4.2.1

Python version

3.13.0a5

What happened?

================================================================================================= FAILURES ==================================================================================================
_________________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-correct] __________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:496: in test_typed_dict
    check_type(value, DummyDict)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
________________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-missing_x] _________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_________________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-wrong_y] __________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_____________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-missing_y_error] ______________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_______________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-missing_y_ok] _______________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:496: in test_typed_dict
    check_type(value, DummyDict)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_________________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-wrong_x] __________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_______________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-unknown_key] ________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
_________________________________________________________________________ TestTypedDict.test_typed_dict[typing_extensions-not_dict] _________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:494: in test_typed_dict
    pytest.raises(TypeCheckError, check_type, value, DummyDict).match(error_re)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
______________________________________________________________________ TestTypedDict.test_inconsistent_keys_invalid[typing_extensions] ______________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:502: in test_inconsistent_keys_invalid
    pytest.raises(
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
__________________________________________________________________________ TestTypedDict.test_notrequired_pass[typing_extensions] ___________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:516: in test_notrequired_pass
    check_type({"x": 8}, DummyDict)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks
__________________________________________________________________________ TestTypedDict.test_notrequired_fail[typing_extensions] ___________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:531: in test_notrequired_fail
    check_type({"x": 1, "y": "foo"}, DummyDict)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:106: in check_type
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:783: in check_type_internal
    if not isinstance(value, origin_type):
/home/ben/src/forks/typeguard/_e/lib64/python3.13/site-packages/typing_extensions.py:951: in __subclasscheck__
    raise TypeError('TypedDict does not support instance and class checks')
E   TypeError: TypedDict does not support instance and class checks

How can we reproduce the bug?

$ gh repo clone agronholm/typeguard
$ cd typeguard
$ git checkout 4.2.1
$ python3.13 --version
Python 3.13.0a5
$ . _e/bin/activate
$ python3.13 -m venv _e
(_e) $ pip install -e .[test]
(_e) $ python -m pytest
musicinmybrain commented 7 months ago

This is very similar to https://github.com/agronholm/typeguard/issues/443, but it seems to be specific to Python 3.13, and occurs in a release that already contains d481a51dd4cb347621b99e144f935e0848977f6e.

agronholm commented 7 months ago

Yep, I'm aware of this, and I think this is caused by typing_extensions not yet supporting Python 3.13. Typeguard relies on typing_extensions.is_typeddict() to recognize typed dicts from both that library and the standard library.

musicinmybrain commented 7 months ago

Thanks for the response. If the problem is in typing_extensions, I wonder if they know about it. Release 4.11.0 advertises Python 3.13.0a5 compatibility, and Python 3.13 appears to be in their test matrix.

agronholm commented 7 months ago

I need to thoroughly check this before filing any issue with them.

musicinmybrain commented 7 months ago

Ok! No big hurry – I’ll track this issue. Thanks for looking into it, and please let me know if there’s anything I can do.

agronholm commented 7 months ago

It looks like they're no longer using typing.TypedDict as typing_extensions.TypedDict, so I need to change the dependencies again.

agronholm commented 7 months ago

Yeah, this is definitely fixable on my side, but I need a good night's rest to wrap my head around the solution.

agronholm commented 6 months ago

This was fixed via #460.