-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: simple return types #54786
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
TYP: simple return types #54786
Conversation
@@ -110,7 +110,7 @@ | |||
) | |||
|
|||
|
|||
IntervalSideT = Union[TimeArrayLike, np.ndarray] | |||
IntervalSide = Union[TimeArrayLike, np.ndarray] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...T is often used for TypeVars
pandas/core/computation/expr.py
Outdated
@@ -349,8 +350,8 @@ class BaseExprVisitor(ast.NodeVisitor): | |||
preparser : callable | |||
""" | |||
|
|||
const_type: type[Term] = Constant | |||
term_type = Term | |||
const_type: ClassVar[type[Constant]] = Constant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably have one PR just focused on making ClassVars more explicit (type checkers have difficulties determining whether they are class or instance variables).
@@ -770,6 +772,7 @@ def value_counts( | |||
mask = ids != -1 | |||
ids, val = ids[mask], val[mask] | |||
|
|||
lab: Index | np.ndarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern happens quite often because of mypy's early binding assumption (first declaration, even if only in one branch, determines the type). I prefer pyright's behavior:
if foo():
a = 1 # mypy: a is of type int (in this branch, in all other branches, and after the if/else)
# pyright: a is of type int in this branch
else:
a = "1" # mypy error!
# pyright: a is of type str in this branch
# pyright: a is of type int | str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real opinion here - mypy forces us to be more explicit for readers prior to branching which I think is a plus.
@@ -770,6 +772,7 @@ def value_counts( | |||
mask = ids != -1 | |||
ids, val = ids[mask], val[mask] | |||
|
|||
lab: Index | np.ndarray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real opinion here - mypy forces us to be more explicit for readers prior to branching which I think is a plus.
Thank you @rhshadrach for your thorough review! I think I addressed your comments as best as I can. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks @twoertwein |
hm, the docs timed out on main as well - did the annotation cause the docs to fail? |
I think that's unrelated (my running theory is that something processing the whatsnew files is not parallel safe and hanging) |
* Return None * Return simple types * ruff false positive * isort+mypy * typo, use " for cast * SingleArrayManager.dtype can also be a numpy dtype * comments + test assert on CI * wider return types at the cost of one fewer mypy ignore * DatetimeArray reaches IntervalArray._combined * avoid some ignores * remove assert False
"simple" meaning, non-unions and non-overload return types (at least in most cases).
xref #47521
edit: sorry for changes in many files - I grep'ed for missing return types inferred by pyright and then fixed the resulting type errors.