Skip to content

Unexpected keyword argument #48914

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

Conversation

shalearkane
Copy link
Contributor

@shalearkane shalearkane commented Oct 2, 2022

This fixed unexpected-keyword-argument warnings from pylint on one file.
The other warnings produced were already expected to be caught in tests.

@MarcoGorelli MarcoGorelli self-requested a review October 2, 2022 18:14
@shalearkane shalearkane closed this Oct 2, 2022
@shalearkane shalearkane force-pushed the unexpected-keyword-argument branch from d009049 to b0237ed Compare October 2, 2022 18:46
@shalearkane shalearkane reopened this Oct 2, 2022
Signed-off-by: Soumik Dutta <[email protected]>
Signed-off-by: Soumik Dutta <[email protected]>
Signed-off-by: Soumik Dutta <[email protected]>
@shalearkane
Copy link
Contributor Author

shalearkane commented Oct 2, 2022

pre-commit is failing because I am using Optional type annotation with the older syntax Optional[type] as the newer syntax type | None is only supported on Python 3.10+

@MarcoGorelli
Copy link
Member

pre-commit is failing because I am using Optional type annotation with the older syntax Optional[type] as the newer syntax type | None is only supported on Python 3.10+

it's supported with from __future__ import annotations, which is at the top of the file

Comment on lines +743 to +745
name: Hashable | None = None,
copy: bool | None = None,
dtype=None,
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your PR

I don't think this is the right fix, as these arguments (name, copy, ...) get passed to NumericIndex, rather than to _constructor

Copy link
Contributor Author

@shalearkane shalearkane Oct 3, 2022

Choose a reason for hiding this comment

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

Yes, I looked into the code. Classes ExtensionIndex, MultiIndex and NumericIndex inherits from the base class Index.

And

  • MultiIndex and
  • RangeIndex (which inherits from NumericIndex)

is overriding the _constructor method.

So should I include the function arguments in the _constructor method of those classes too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

classes

Copy link
Member

Choose a reason for hiding this comment

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

wait, this isn't resolved - I think the issue is that pylint can't tell that @cache_readonly makes _constructor act like a property and that it doesn't take arguments

I'll have another look later

@mroeschke mroeschke added the Code Style Code style, linting, code_checks label Oct 3, 2022
Comment on lines +743 to +745
name: Hashable | None = None,
copy: bool | None = None,
dtype=None,
Copy link
Member

Choose a reason for hiding this comment

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

wait, this isn't resolved - I think the issue is that pylint can't tell that @cache_readonly makes _constructor act like a property and that it doesn't take arguments

I'll have another look later

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @shalearkane for your PR

I've had a closer look, and I don't think we should enable this check

cache_readonly acts like a property, but pylint isn't aware of this and so it thinks that the arguments that are passed to whetever function the property returns are being passed to the property itself

mypy already checks this, and the way pandas gets mypy to recognise that cache_readonly is a property is

cache_readonly = property

So, I'll add this to the list of checks we probably can't turn off

Closing for now then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants