Visitar URL original
bpo-44919: Fix issue when TypedDict subtypes ignore any other metaclass by uriyyo · Pull Request #28057 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20250819001500/https://github.com/python/cpython/pull/28057
Skip to content

bpo-44919: Fix issue when TypedDict subtypes ignore any other metaclass #28057

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 1 commit into from

Conversation

uriyyo
Copy link
Member

@uriyyo uriyyo commented Aug 30, 2021 •

@gvanrossum gvanrossum changed the title bpo-44919: Fix issue when TypedDict subtypes ignore any other mсs bpo-44919: Fix issue when TypedDict subtypes ignore any other metaclass Aug 30, 2021
Copy link
Member

@sobolevn sobolevn left a comment •

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on my problem! 👍
This is definetelly a fix for it.

Let's see what more knowledgeable people will say.

class _CustomTypedDictMeta(type(_Foo)):
pass

class _NewTypedDict(_Foo, metaclass=_CustomTypedDictMeta):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need an explicit test for case when we try to create a custom _TypedDict subclass that uses wrong metaclass? class _NewTypedDict(_Foo, metaclass=Wrong):

Copy link
Member Author

@uriyyo uriyyo Sep 4, 2021 •

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In such case it will simply fail because of metaclass conflict:

class _Foo(TypedDict):
    pass


class Wrong(type):
    pass


class _NewTypedDict(_Foo, metaclass=Wrong):
    pass
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

I don't know if we should cover this case. I think it will be enough to verify that TypedDict subclass is an instance of a correct metaclass as it does at line 4307:

self.assertIsInstance(_NewTypedDict, _CustomTypedDictMeta)

@ambv
Copy link
Contributor

ambv commented Sep 28, 2021

Discussion on the issue.

@uriyyo uriyyo closed this May 3, 2022
@uriyyo uriyyo deleted the fix-issue-44919 branch May 3, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants