You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Subclasses of mailbox.Mailbox not recognized as such #14935
I'm 90% sure this should be acceptable, but running 1.18.2 on this code produces the error:
mailbox02.py:14: error: Return type "mbox" of "open" incompatible with return type "Mailbox[Message[str, str]]" in supertype "MailboxFactory" [override]
Found 1 error in 1 file (checked 1 source file)
Similar errors happen for other Mailbox subclasses as well.
The problem is that Mailbox is generic over the message type (_MessageT), which is invariant and defaults to Message[str, str]. Easy workaround is to use mailbox.Mailbox[Any], although we should probably change the default for Mailbox in typeshed for cases like this.
Activity
srittau commentedon Oct 30, 2025
The problem is that
Mailboxis generic over the message type (_MessageT), which is invariant and defaults toMessage[str, str]. Easy workaround is to usemailbox.Mailbox[Any], although we should probably change the default forMailboxin typeshed for cases like this.srittau commentedon Oct 30, 2025
In fact, we can make the type variable covariant in typeshed, which should fix this problem.
Various improvements for the mailbox stubs
Various improvements for the mailbox stubs (python#14950)