Skip to content
Discussion options

You must be logged in to vote

You're right that the diagnostic is technically accurate, but the reason it fires is more subtle than "Mapped isn't a str," and it explains why none of your workarounds helped.

What's actually happening

Mapped is a descriptor. When you access it on an instance, pyright correctly resolves __get__:

reveal_type(Host().hostname)  # str
reveal_type(Host.hostname)    # Mapped[str]

But during protocol matching, pyright does not apply the descriptor. It compares the member's declared type (Mapped[str]) against the protocol member, not the __get__-resolved type (str). Combined with the invariance rule for mutable protocol attributes, Mapped[str] has to equal str, and it doesn't.

This is also why s…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@MajorDallas
Comment options

@rchiodo
Comment options

@MajorDallas
Comment options

Answer selected by MajorDallas
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