Skip to content

TYP: Enable pyright's reportInconsistentConstructor #54398

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

Merged
merged 2 commits into from
Aug 4, 2023
Merged

TYP: Enable pyright's reportInconsistentConstructor #54398

merged 2 commits into from
Aug 4, 2023

Conversation

twoertwein
Copy link
Member

reportInconsistentConstructor checks that __new__ and __init__ should be consistent (argument names and their types)

@twoertwein twoertwein added the Typing type annotations, mypy/pyright type checking label Aug 4, 2023
@@ -189,9 +189,6 @@ def ndim(self) -> int:


class Constant(Term):
def __init__(self, value, env, side=None, encoding=None) -> None:
super().__init__(value, env, side=side, encoding=encoding)
Copy link
Member Author

Choose a reason for hiding this comment

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

Should not be needed, just calls the parent constructor (and uses value instead of name)

@@ -573,7 +573,7 @@ class PeriodProperties(Properties):
class CombinedDatetimelikeProperties(
DatetimeProperties, TimedeltaProperties, PeriodProperties
):
def __new__(cls, data: Series):
def __new__(cls, data: Series): # pyright: ignore[reportInconsistentConstructor]
Copy link
Member Author

Choose a reason for hiding this comment

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

The parent __init__ expect orig as a second argument. Just ignoring the error as the comment indicates that this class is never "really" instantiated.

@twoertwein twoertwein changed the title Enable pyright's reportInconsistentConstructor TYP: Enable pyright's reportInconsistentConstructor Aug 4, 2023
@twoertwein
Copy link
Member Author

Renaming the arguments (value -> name) technically changes the runtime behavior (if code calls the renamed argument as a keyword argument - probably not as it is the first argument) @jbrockmendel

@jbrockmendel
Copy link
Member

if code calls the renamed argument as a keyword argument - probably not as it is the first argument

AFAICT none of the affected places are public, so I don't think thats a problem

@@ -732,6 +732,7 @@ include = ["pandas", "typings"]
exclude = ["pandas/tests", "pandas/io/clipboard", "pandas/util/version"]
# enable subset of "strict"
reportDuplicateImport = true
reportInconsistentConstructor = true
Copy link
Member

Choose a reason for hiding this comment

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

In a follow up, could we enable strict mode and then turn off the checks that don't pass (with todos) or are not relevant like we did with mypy?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could enable strict and disable many of its rules (and I think we had that in the past). I think the pyright maintainer recommended that we prioritize enabling reportGeneralTypeIssues (we have a large blacklist in pyright_reportGeneralTypeIssues.json) before enabling strict as it also changes some of its behavior.

Copy link
Member

Choose a reason for hiding this comment

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

Okay sounds good

@@ -1,4 +1,3 @@
# this becomes obsolete when reportGeneralTypeIssues can be enabled in pyproject.toml
Copy link
Member Author

Choose a reason for hiding this comment

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

Pyright uses a stricter JSON parser - comments are not part of the JSON syntax.

(There are much newer versions of pyright but there are too many things we would need to change at the moment.)

@mroeschke mroeschke added this to the 2.1 milestone Aug 4, 2023
@mroeschke mroeschke merged commit 861b2fb into pandas-dev:main Aug 4, 2023
@mroeschke
Copy link
Member

Thanks @twoertwein

@twoertwein twoertwein deleted the reportInconsistentConstructor branch August 9, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants