Skip to content

How to correctly handle initMethodSelfParamTypeVar errors #7863

Answered by erictraut
runfalk asked this question in Q&A
Discussion options

You must be logged in to vote

The typing spec was recently updated to clarify that class-scoped type variables cannot be used in the self parameter of an __init__ method, so pyright's error is correct here.

You can use method-scoped type variables in this case, so that's the approach I'd recommend. Create a new type variable (say, T), and change your last overload signature to be:

    @t.overload
    def __init__(self: "FrozenMap[str, T]", **kwargs: T) -> None: ...

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@runfalk
Comment options

@erictraut
Comment options

Answer selected by runfalk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants