Skip to content

Error isn't provided when TypeVar is defined in both outer and inner class scopes #10479

Closed
@erictraut

Description

@erictraut

PEP 484 says "A generic class nested in another generic class cannot use same type variables. The scope of the type variables of the outer class doesn't cover the inner one".

It provides the following example:

from typing import Generic, Iterable, TypeVar

T = TypeVar('T')
S = TypeVar('S')

class Outer(Generic[T]):
    class Bad(Iterable[T]):       # Error
        ...

Mypy does not emit an error in this case even though PEP 484 says it's not allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions