Closed kloczek closed 3 months ago
Pyupgrade is being overly zealous here, and I would use ruff
instead of pyupgrade
for this anyway.
Also it'll be around 5 months until 3.8 reaches end of life: https://devguide.python.org/versions/#supported-versions
Pyupgrade is being overly zealous here, and I would use
ruff
instead ofpyupgrade
for this anyway.
ruff
is not performing any python version code updates.
It does many other thing so both tools should be used (combined).
If you will try to use ruff on current code it will generate empty patch.
Also it'll be around 5 months until 3.8 reaches end of life: https://devguide.python.org/versions/#supported-versions
Yep my mistake .. nevertheless it is relatively close to 3.8 EOS.
Pyupgrade is being overly zealous here, and I would use
ruff
instead ofpyupgrade
for this anyway.
ruff
is not performing any python version code updates. It does many other thing so both tools should be used (combined). If you will try to use ruff on current code it will generate empty patch.
Did you update requires-python
in pyproject.toml
before running ruff
?
Did you update
requires-python
inpyproject.toml
before runningruff
?
Just tested that
[tkloczko@pers-jacek SOURCES]$ ls -l python-typeguard-ruff.patch python-typeguard-pyupgrade_py39.patch
-rw-r--r-- 1 tkloczko tkloczko 24613 May 25 14:56 python-typeguard-pyupgrade_py39.patch
-rw-r--r-- 1 tkloczko tkloczko 3602 May 25 14:56 python-typeguard-ruff.patch
Typeguard is somewhat of a special case in that it needs to still use the "deprecated" types from typing
, so an upgrade should not make too many changes in that regard.
Why is this an issue at all anyway?
And after apply pyupgrade_py39 generated ruff sill generates even bigger patch
-rw-r--r-- 1 tkloczko tkloczko 4985 May 25 14:58 python-typeguard-ruff.patch
Why is this an issue at all anyway?
Quote from opening this ticket
Looks like current code is not ready to be upgraded to python 3.9+ using pyupgrade --py39-plus and it causes test suite fails.
Why would you perform such an action anyways before 3.8 is EOL? I routinely upgrade my projects in such a manner when I drop support for an obsolete Python version.
In fact, this happens automatically when I bump python_requires
.
I think that above shows clearly that ruff and pyupgrade are doing different checks.
Why would you perform such an action anyways before 3.8 is EOL? I routinely upgrade my projects in such a manner when I drop support for an obsolete Python version.
Because in distro on which I'm working currently is used python 3.11 (soon will be migration to 3.12) and many code can be dropped with assumption that generated packages will be used with exact version.
Nevertheless pyupgrade generates patch which breaks test suite.
In fact, this happens automatically when I bump python_requires.
python_requires
is used with setup.{py|cfg}.
With pyproject.toml is used requires-python
.
If you want to modify typeguard downstream, you're free to do so but you will do so at your own risk and expense. Pyupgrade making a patch that fails the test suite isn't my problem. When the time comes, I will use ruff
to upgrade the code base as needed.
If you want to modify typeguard downstream,
I have no enough knowledge about your module. This is why I've reported what I found.
You can ignore this issue and fact you didn't know that ruff is not doing what pyupgrade is doing but issue still remains ..
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.2.1
Python version
3.10.14
What happened?
Looks like current code is not ready to be upgraded to python 3.9+ using
pyupgrade --py39-plus
and it causes test suite fails.Here is pytest output:
```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib64/python3.10/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages + /usr/bin/pytest -ra -m 'not network' ==================================================================================== test session starts ==================================================================================== platform linux -- Python 3.10.14, pytest-8.2.1, pluggy-1.5.0 rootdir: /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1 configfile: pyproject.toml testpaths: tests plugins: typeguard-4.2.1, asyncio-0.23.7 asyncio: mode=strict collected 455 items tests/mypy/test_type_annotations.py .. [ 0%] tests/test_checkers.py ..................................................................s.s........................................................F.........F...................... [ 35%] ............FF.................. [ 42%] tests/test_importhook.py ... [ 42%] tests/test_instrumentation.py ........xxx..............................................xxx...................................... [ 64%] tests/test_plugins.py . [ 64%] tests/test_pytest_plugin.py .. [ 65%] tests/test_suppression.py ....... [ 66%] tests/test_transformer.py ................................................s............................... [ 84%] tests/test_typechecked.py ..................................................... [ 95%] tests/test_union_transformer.py ..F..F.....F [ 98%] tests/test_utils.py ..... [ 99%] tests/test_warn_on_error.py .. [100%] ========================================================================================= FAILURES ========================================================================================== ______________________________________________________________________________ TestUnion.test_typing_type_fail ______________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_checkers.py:780: in test_typing_type_fail pytest.raises(TypeCheckError, check_type, 1, Union[str, Collection]).match( E AssertionError: Regex pattern did not match. E Regex: 'int did not match any element in the union:\n str: is not an instance of str\n Collection: is not an instance of collections.abc.Collection' E Input: 'int did not match any element in the union:\n str: is not an instance of str\n collections.abc.Collection: is not an instance of collections.abc.Collection' _______________________________________________________________________ TestTypevar.test_collection_constraints_fail ________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_checkers.py:857: in test_collection_constraints_fail pytest.raises(TypeCheckError, check_type, {1, 2}, TTypingConstrained).match( E AssertionError: Regex pattern did not match. E Regex: 'set does not match any of the constraints \\(List\\[int\\], AbstractSet\\[str\\]\\)' E Input: 'set does not match any of the constraints (list[int], AbstractSet[str])' _______________________________________________________________________________ TestRecursiveType.test_valid ________________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_checkers.py:1054: in test_valid check_type({"a": [1, 2, 3]}, JSONType) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_functions.py:106: in check_type check_type_internal(value, expected_type, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:777: in check_type_internal checker(value, origin_type, args, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:416: in check_union check_type_internal(value, type_, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:777: in check_type_internal checker(value, origin_type, args, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:235: in check_mapping check_type_internal(v, value_type, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:784: in check_type_internal warnings.warn( E typeguard.TypeHintWarning: Skipping type check against 'JSONType'; this looks like a string-form forward reference imported from another module ________________________________________________________________________________ TestRecursiveType.test_fail ________________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_checkers.py:1076: in test_fail check_type({"a": (1, 2, 3)}, JSONType) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_functions.py:106: in check_type check_type_internal(value, expected_type, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:777: in check_type_internal checker(value, origin_type, args, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:416: in check_union check_type_internal(value, type_, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:777: in check_type_internal checker(value, origin_type, args, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:235: in check_mapping check_type_internal(v, value_type, memo) /home/tkloczko/rpmbuild/BUILDROOT/python-typeguard-4.2.1-2.fc37.x86_64/usr/lib/python3.10/site-packages/typeguard/_checkers.py:784: in check_type_internal warnings.warn( E typeguard.TypeHintWarning: Skipping type check against 'JSONType'; this looks like a string-form forward reference imported from another module _____________________________________________________ test_union_transformer[str | Union[int | bytes, set]-Union[str, int, bytes, Set]] _____________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_union_transformer.py:45: in test_union_transformer assert evaluated_repr == expected E AssertionError: assert 'Union[str, int, bytes, set]' == 'Union[str, int, bytes, Set]' E E - Union[str, int, bytes, Set] E ? ^ E + Union[str, int, bytes, set] E ? ^ ______________________________________ test_union_transformer[str | int | Callable[[], bytes | set]-Union[str, int, Callable[[], Union[bytes, Set]]]] _______________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_union_transformer.py:45: in test_union_transformer assert evaluated_repr == expected E AssertionError: assert 'Union[str, i...bytes, set]]]' == 'Union[str, i...bytes, Set]]]' E E - Union[str, int, Callable[[], Union[bytes, Set]]] E ? ^ E + Union[str, int, Callable[[], Union[bytes, set]]] E ? ^ __________________________________________________________________ test_union_transformer[tuple[int, ...]-Tuple[int, ...]] __________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_union_transformer.py:45: in test_union_transformer assert evaluated_repr == expected E AssertionError: assert 'tuple[int, ...]' == 'Tuple[int, ...]' E E - Tuple[int, ...] E ? ^ E + tuple[int, ...] E ? ^ ========================================================================================= XFAILURES ========================================================================================= ___________________________________________________________________________ test_inner_class_method[typechecked] ____________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:102: in test_inner_class_method retval = dummymodule.Outer().create_inner() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:116: in create_inner def create_inner(self) -> "Inner": E NameError: name 'Inner' is not defined _________________________________________________________________________ test_inner_class_classmethod[typechecked] _________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:108: in test_inner_class_classmethod retval = dummymodule.Outer.create_inner_classmethod() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:120: in create_inner_classmethod def create_inner_classmethod(cls) -> "Inner": E NameError: name 'Inner' is not defined ________________________________________________________________________ test_inner_class_staticmethod[typechecked] _________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:114: in test_inner_class_staticmethod retval = dummymodule.Outer.create_inner_staticmethod() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:124: in create_inner_staticmethod def create_inner_staticmethod() -> "Inner": E NameError: name 'Inner' is not defined ____________________________________________________________________________ test_inner_class_method[importhook] ____________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:102: in test_inner_class_method retval = dummymodule.Outer().create_inner() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:116: in create_inner def create_inner(self) -> "Inner": E NameError: name 'Inner' is not defined _________________________________________________________________________ test_inner_class_classmethod[importhook] __________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:108: in test_inner_class_classmethod retval = dummymodule.Outer.create_inner_classmethod() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:120: in create_inner_classmethod def create_inner_classmethod(cls) -> "Inner": E NameError: name 'Inner' is not defined _________________________________________________________________________ test_inner_class_staticmethod[importhook] _________________________________________________________________________ /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/test_instrumentation.py:114: in test_inner_class_staticmethod retval = dummymodule.Outer.create_inner_staticmethod() /home/tkloczko/rpmbuild/BUILD/typeguard-4.2.1/tests/dummymodule.py:124: in create_inner_staticmethod def create_inner_staticmethod() -> "Inner": E NameError: name 'Inner' is not defined ================================================================================== short test summary info ================================================================================== SKIPPED [1] tests/test_checkers.py:504: 'NotRequired' not found in 'typing' SKIPPED [1] tests/test_checkers.py:516: 'NotRequired' not found in 'typing' SKIPPED [1] tests/test_transformer.py:1219: Requires Python < 3.10 XFAIL tests/test_instrumentation.py::test_inner_class_method[typechecked] - No workaround for this has been implemented yet XFAIL tests/test_instrumentation.py::test_inner_class_classmethod[typechecked] - No workaround for this has been implemented yet XFAIL tests/test_instrumentation.py::test_inner_class_staticmethod[typechecked] - No workaround for this has been implemented yet XFAIL tests/test_instrumentation.py::test_inner_class_method[importhook] - No workaround for this has been implemented yet XFAIL tests/test_instrumentation.py::test_inner_class_classmethod[importhook] - No workaround for this has been implemented yet XFAIL tests/test_instrumentation.py::test_inner_class_staticmethod[importhook] - No workaround for this has been implemented yet FAILED tests/test_checkers.py::TestUnion::test_typing_type_fail - AssertionError: Regex pattern did not match. FAILED tests/test_checkers.py::TestTypevar::test_collection_constraints_fail - AssertionError: Regex pattern did not match. FAILED tests/test_checkers.py::TestRecursiveType::test_valid - typeguard.TypeHintWarning: Skipping type check against 'JSONType'; this looks like a string-form forward reference imported from another module FAILED tests/test_checkers.py::TestRecursiveType::test_fail - typeguard.TypeHintWarning: Skipping type check against 'JSONType'; this looks like a string-form forward reference imported from another module FAILED tests/test_union_transformer.py::test_union_transformer[str | Union[int | bytes, set]-Union[str, int, bytes, Set]] - AssertionError: assert 'Union[str, int, bytes, set]' == 'Union[str, int, bytes, Set]' FAILED tests/test_union_transformer.py::test_union_transformer[str | int | Callable[[], bytes | set]-Union[str, int, Callable[[], Union[bytes, Set]]]] - AssertionError: assert 'Union[str, i...bytes, set]]]' == 'Union[str, i...bytes, Set]]]' FAILED tests/test_union_transformer.py::test_union_transformer[tuple[int, ...]-Tuple[int, ...]] - AssertionError: assert 'tuple[int, ...]' == 'Tuple[int, ...]' =================================================================== 7 failed, 439 passed, 3 skipped, 6 xfailed in 11.54s ==================================================================== ```This issue is not urgent but it would be good to make
typeguard
code ready for pypugrade (python 3.8 will be EOSed next month) or report to pypugrade that it messes with code in some cases.How can we reproduce the bug?
filter all code by
find . -name \*.py | xargs pyupgrade --py39-plus
and than build and test moduleHere is patch generated by pyuprade