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

[PEP 695] Unexpected var-annotated error #17630

Closed
jolaf opened this issue Aug 3, 2024 · 1 comment · Fixed by #17776
Closed

[PEP 695] Unexpected var-annotated error #17630

jolaf opened this issue Aug 3, 2024 · 1 comment · Fixed by #17776
Labels
bug mypy got something wrong topic-pep-695 Issues related to PEP 695 syntax

Comments

@jolaf
Copy link
Contributor

jolaf commented Aug 3, 2024

The following code:

from __future__ import annotations

class A:
    class B[T]:
        def __get__(self, instance: A, owner: type[A]) -> T:
            return None
    f = B[int]()

a = A()
v = a.f

print("OK")

produces the following output:

test.py: note: In member "__get__" of class "B":
test.py:5:59: error: A function returning TypeVar should receive at least one argument containing the same TypeVar  [type-var]
            def __get__(self, instance: A, owner: type[A]) -> T:
                                                              ^
test.py:6:20: error: Incompatible return value type (got "None", expected "T")  [return-value]
                return None
                       ^~~~
test.py: note: At top level:
test.py:10:5: error: Need type annotation for "v"  [var-annotated]
    v = a.f
        ^~~
Found 3 errors in 1 file (checked 1 source file)

Here the first error [type-var] is due to #17596.

The second error [return-value] is legitimate and appears here because of synthetic nature of this test, extracted from much more complicated code.

The third error [var-annotated] is the essence of this issue.
It looks like a false positive to me.

$ mypy --version
mypy 1.11.1 (compiled: yes)

$ python --version
Python 3.12.3

$ lsb_release -d
No LSB modules are available.
Description:	Ubuntu 24.04 LTS
@jolaf jolaf added the bug mypy got something wrong label Aug 3, 2024
@jolaf jolaf changed the title Unexpected var-annotated error [PEP 695] Unexpected var-annotated error Aug 3, 2024
@jolaf
Copy link
Contributor Author

jolaf commented Aug 3, 2024

It should be tagged topic-pep-695.

@JelleZijlstra JelleZijlstra added the topic-pep-695 Issues related to PEP 695 syntax label Aug 3, 2024
@JukkaL JukkaL closed this as completed in f68f76d Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-pep-695 Issues related to PEP 695 syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants