Skip to content

[PEP 695] Nested generic class fails to typecheck #17596

Closed
@jolaf

Description

@jolaf

The following code:

class A:
    class B[T]:
        def f(self) -> T: ...

produces the following output:

$ mypy --enable-incomplete-feature=NewGenericSyntax test.pyi 
test.pyi: note: In member "f" of class "B":
test.pyi:3:24: error: A function returning TypeVar should receive at least one argument containing the same TypeVar  [type-var]
            def f(self) -> T: ...
                           ^
Found 1 error in 1 file (checked 1 source file)

This looks like a false positive to me.

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

$ python3 --version
Python 3.12.3

$ lsb_release -d
No LSB modules are available.
Description:	Ubuntu 24.04 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-pep-695Issues related to PEP 695 syntax

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions