Skip to content
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

Pass **kwds in MetaHasDescriptors __new__ and __init__ #881

Merged
merged 1 commit into from
Oct 21, 2023

Conversation

fleming79
Copy link
Contributor

This is a modest change that adds **kwds to MetaHasDescriptors __new__ and __init__ to match the signature defined in the Python docs:

metaclass(name, bases, namespace, **kwds)

This enables the usage __init_subclass__ without having to overload MetaHasDescriptors to intercept the arguments passed to a subclass.

Trivial example

from traitlets import HasTraits
class Philosopher(HasTraits):
    def __init_subclass__(cls, /, default_name, **kwargs):
        super().__init_subclass__(**kwargs)
        cls.default_name = default_name

class AustralianPhilosopher(Philosopher, default_name="Bruce"):
    pass

Before

image

After

image

@fleming79 fleming79 changed the title Pass **kwds inMetaHasDescriptors __new__ and __init__ Pass **kwds in MetaHasDescriptors __new__ and __init__ Oct 14, 2023
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

Sounds reasonable to me, thank you!

@blink1073 blink1073 merged commit 936525b into ipython:main Oct 21, 2023
27 of 31 checks passed
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.

2 participants