Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some test regressions on Python 3.14.0a1 #502

Open
2 tasks done
musicinmybrain opened this issue Nov 22, 2024 · 2 comments
Open
2 tasks done

Some test regressions on Python 3.14.0a1 #502

musicinmybrain opened this issue Nov 22, 2024 · 2 comments
Labels

Comments

@musicinmybrain
Copy link

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

Current master, b6a7e43

Python version

3.14.0a1

What happened?

With pytest -W 'ignore::DeprecationWarning':

================================================================================================= FAILURES ==================================================================================================
________________________________________________________________________________________ TestRecursiveType.test_fail ________________________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_checkers.py:1411: in test_fail
    check_type({"a": (1, 2, 3)}, JSONType)
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:107: in check_type   
    check_type_internal(value, expected_type, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:946: in check_type_internal
    checker(value, origin_type, args, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:427: in check_union   
    raise TypeCheckError(f"did not match any element in the union:\n{formatted_errors}")
E   typeguard.TypeCheckError: dict did not match any element in the union:
E     str: is not an instance of str
E     float: is neither float or int
E     bool: is not an instance of bool
E     NoneType: is not an instance of NoneType
E     List[annotationlib.JSONType]: is not a list
E     Dict[str, annotationlib.JSONType]: value of key 'a' did not match any element in the union:
E       str: is not an instance of str
E       float: is neither float or int
E       bool: is not an instance of bool
E       NoneType: is not an instance of NoneType
E       List[annotationlib.JSONType]: is not a list
E       Dict[str, annotationlib.JSONType]: is not a dict

During handling of the above exception, another exception occurred:
/home/ben/src/forks/typeguard/tests/test_checkers.py:1392: in test_fail
    with pytest.raises(
E   AssertionError: Regex pattern did not match.
E    Regex: "dict did not match any element in the union:\n  str: is not an instance of str\n  float: is neither float or int\n  bool: is not an instance of bool\n  NoneType: is not an instance of NoneType\n  List\\[JSONType\\]: is not a list\n  Dict\\[str, JSONType\\]: value of key 'a' did not match any element in the union:\n    str: is not an instance of str\n    float: is neither float or int\n    bool: is not an instance of bool\n    NoneType: is not an instance of NoneType\n    List\\[JSONType\\]: is not a list\n    Dict\\[str, JSONType\\]: is not a dict"
E    Input: "dict did not match any element in the union:\n  str: is not an instance of str\n  float: is neither float or int\n  bool: is not an instance of bool\n  NoneType: is not an instance of NoneType\n  List[annotationlib.JSONType]: is not a list\n  Dict[str, annotationlib.JSONType]: value of key 'a' did not match any element in the union:\n    str: is not an instance of str\n    float: is neither float or int\n    bool: is not an instance of bool\n    NoneType: is not an instance of NoneType\n    List[annotationlib.JSONType]: is not a list\n    Dict[str, annotationlib.JSONType]: is not a dict"
____________________________________________________________________________________ test_typevar_forwardref[importhook] ____________________________________________________________________________________
/home/ben/src/forks/typeguard/tests/test_instrumentation.py:333: in test_typevar_forwardref
    instance = dummymodule.typevar_forwardref(dummymodule.DummyClass)
/home/ben/src/forks/typeguard/tests/dummymodule.py:339: in typevar_forwardref
    def typevar_forwardref(x: Type[T]) -> T:
/home/ben/src/forks/typeguard/src/typeguard/_functions.py:137: in check_argument_types
    check_type_internal(value, annotation, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:946: in check_type_internal
    checker(value, origin_type, args, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:481: in check_class
    check_typevar(value, expected_class, (), memo, subclass_check=True)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:538: in check_typevar
    check_type_internal(value, annotation, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:946: in check_type_internal
    checker(value, origin_type, args, memo)
/home/ben/src/forks/typeguard/src/typeguard/_checkers.py:504: in check_class   
    raise TypeCheckError(f"is not a subclass of {qualified_name(expected_class)}")
E   typeguard.TypeCheckError: argument "x" (class dummymodule.DummyClass) is not a subclass of dummymodule.DummyClass
========================================================================================== short test summary info ==========================================================================================
FAILED tests/test_checkers.py::TestRecursiveType::test_fail - AssertionError: Regex pattern did not match.
FAILED tests/test_instrumentation.py::test_typevar_forwardref[importhook] - typeguard.TypeCheckError: argument "x" (class dummymodule.DummyClass) is not a subclass of dummymodule.DummyClass
============================================================================ 2 failed, 474 passed, 4 skipped, 9 xfailed in 1.39s ============================================================================

Without -W 'ignore::DeprecationWarning', I also see a lot of

E   DeprecationWarning: ForwardRef._evaluate is a private API and is retained for compatibility, but will be removed in Python 3.16. Use ForwardRef.evaluate() or typing.evaluate_forward_ref() instead.

How can we reproduce the bug?

$ gh repo clone agroholm/typeguard
$ cd typeguard
$ python3.14 --version
Python 3.14.0a1
$ python3.14 -m venv _e
$ . _e/bin/activate
(_e) $ pip install -e .[test]
(_e) $ pytest -W 'ignore::DeprecationWarning'
@musicinmybrain
Copy link
Author

FAILED tests/test_checkers.py::TestRecursiveType::test_fail - AssertionError: Regex pattern did not match.

The output now has annotationlib.JSONType in place of just JSONType. I can fix this by adjusting the regex.

E   DeprecationWarning: ForwardRef._evaluate is a private API and is retained for compatibility, but will be removed in Python 3.16. Use ForwardRef.evaluate() or typing.evaluate_forward_ref() instead.

Python 3.14 is adding a public ForwardRef.evaluate() function, so we should just start using it where it is available.

FAILED tests/test_instrumentation.py::test_typevar_forwardref[importhook] - typeguard.TypeCheckError: argument "x" (class dummymodule.DummyClass) is not a subclass of dummymodule.DummyClass

This one I’m not quite sure how to fix.

@musicinmybrain
Copy link
Author

I see that @JelleZijlstra already started working on this in #492.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant