Fixed annotation for typeguard_ignore() to match one for typing.no_type_check()#485
Merged
agronholm merged 3 commits intoagronholm:masterfrom Sep 21, 2024
Merged
Conversation
Contributor
Author
|
Here's the test demonstrating the issue.
from typeguard import install_import_hook
with install_import_hook(('A',)):
import A
try:
from typeguard import typeguard_ignore
except ImportError:
from typing import no_type_check as typeguard_ignore
@typeguard_ignore
def f() -> None:
a: int = "OK"
print(a)
f()$ python3 A.py
OK
$ python3 test.py
OK
$ mypy A.py
A.py:4:5: error: Incompatible import of "typeguard_ignore" (imported name has type "Callable[[_F@no_type_check], _F@no_type_check]", local name has type "Callable[[_F@typeguard_ignore], _F@typeguard_ignore]") [assignment]
from typing import no_type_check as typeguard_ignore
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A.py: note: In function "f":
A.py:8:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment]
a: int = "OK"
^~~~
Found 2 errors in 1 file (checked 1 source file)The second error is expected, but the first one is not. It goes away with this patch. $ python --version
Python 3.12.3
$ pip list | grep typeguard
typeguard 4.3.0
$ mypy --version
mypy 1.11.2 (compiled: yes) |
typeguard_ignore() to match one for typing.no_type_check()
Owner
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trivial fix to make sure
typeguard_ignore()has the same type signature in bothTYPE_CHECKINGand runtime branches.