Skip to content

Should we discuss "scope" of type variables in PEP 484? #249

Closed
@ilevkivskyi

Description

@ilevkivskyi

I did not find any discussion about the "visibility" of type variables. For example, here

from typing import TypeVar, Generic

T = TypeVar('T')

def fun_1(x: T) -> T:
    ...
def fun_2(x: T) -> T:
    ...

class MyClass(Generic[T]):
    def meth_1(self, x: T) -> T:
        ...
    def meth_2(self, x: T) -> T:
        ...

I think the type variable T could take different values in fun_1 and fun_2, but it is always the same for meth_1 and meth_2. I could imagine more complex examples with deeply nested classes and functions. Although it might be obvious for some people, maybe we should discuss "scoping rules" for type variables in the PEP?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions