Skip to content

Add NamedTupleMeta metaclass #11046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Add NamedTupleMeta metaclass #11046

wants to merge 5 commits into from

Conversation

@sobolevn
Copy link
Member Author

Mypy does not like this change:

stdlib/typing.pyi:865: error: Metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

This comment has been minimized.

@sobolevn
Copy link
Member Author

I think the reason is that tuple inherits types that use ABCMeta, so, let's preted that NamedTupleMeta also has ABCMeta.

This comment has been minimized.

@sobolevn
Copy link
Member Author

Now pyright finds some cases where NamedTuple is used together with Enum:

class _ASN1ObjectBase(NamedTuple):
    nid: int
    shortname: str
    longname: str
    oid: str

class _ASN1Object(_ASN1ObjectBase):
    def __new__(cls, oid: str) -> Self: ...
    @classmethod
    def fromnid(cls, nid: int) -> Self: ...
    @classmethod
    def fromname(cls, name: str) -> Self: ...

class Purpose(_ASN1Object, enum.Enum):
    SERVER_AUTH: _ASN1Object
    CLIENT_AUTH: _ASN1Object

Another option for us is to use # type: ignore[misc] on this definition. I will give this a try.

@sobolevn
Copy link
Member Author

:(

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra
Copy link
Member

Sorry, seems like this didn't work out. The linked mypy bug should likely be fixed with special-casing in mypy itself.

@AlexWaygood AlexWaygood deleted the add-namedtuple-metaclass branch October 2, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants