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

Add additional docs for uncooperative ctor deprecation #9498

Merged
merged 4 commits into from Jan 27, 2022

Conversation

The-Compiler
Copy link
Member

Fixes #9488

Probably still needs test adjustments, but I'd like some feedback from @RonnyPfannschmidt if this is the way to go.

def __init__(self, name, parent, spec):
super().__init__(name, parent)
def __init__(self, spec, **kwargs):
super().__init__(**kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

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

@RonnyPfannschmidt would you agree that we should use and recommend **kwargs here too (despite no conflict at the moment), so that we can freely change these arguments if needed in the future?

If so, I wonder if we should always show this deprecation warning if **kwargs are missing, rather than only showing it in case there are conflicts?

Copy link
Member

Choose a reason for hiding this comment

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

the warning was introduced to handle broken code

if we introduce it like this, then we should also take a look at standardizing to kwonly args so we can at some point deprecate positional args to nodes

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

approving to ease process before im off to take the toddler , lets add the * to make it kwonly tho

.. code-block:: python

class CustomItem(pytest.Item):
def __init__(self, additional_arg, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, additional_arg, **kwargs):
def __init__(self, *, additional_arg, **kwargs):

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure about this honestly - while I agree it's a good thing in general, in the context of this deprecation warning, it seems more confusing than useful, no?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @RonnyPfannschmidt, I think we should encourage using kwarg-only in the ctors.

doc/en/deprecations.rst Show resolved Hide resolved
@The-Compiler The-Compiler added the needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch label Jan 11, 2022
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

LGTM!

.. code-block:: python

class CustomItem(pytest.Item):
def __init__(self, additional_arg, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @RonnyPfannschmidt, I think we should encourage using kwarg-only in the ctors.

@@ -18,8 +18,8 @@ def collect(self):


class YamlItem(pytest.Item):
def __init__(self, name, parent, spec):
super().__init__(name, parent)
def __init__(self, spec, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Following discussion above:

Suggested change
def __init__(self, spec, **kwargs):
def __init__(self, *, spec, **kwargs):

@The-Compiler
Copy link
Member Author

Apologies for the delay, I forgot about this. Updated now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[prerelease] Improve cooperate constructor warning
4 participants