Skip to content

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

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)

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

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

3 participants