-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP fixup overloads for reset_index #40200
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
Changes from 4 commits
53da46b
56fd378
1b977ce
7b92ab1
8b404bb
2360b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5119,9 +5119,7 @@ def set_index( | |
return frame | ||
|
||
@overload | ||
# https://github.com/python/mypy/issues/6580 | ||
# Overloaded function signatures 1 and 2 overlap with incompatible return types | ||
def reset_index( # type: ignore[misc] | ||
def reset_index( | ||
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., | ||
drop: bool = ..., | ||
|
@@ -5134,22 +5132,60 @@ def reset_index( # type: ignore[misc] | |
@overload | ||
def reset_index( | ||
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., | ||
drop: bool = ..., | ||
inplace: Literal[True] = ..., | ||
level: Optional[Union[Hashable, Sequence[Hashable]]], | ||
drop: bool, | ||
inplace: Literal[True], | ||
col_level: Hashable = ..., | ||
col_fill: Hashable = ..., | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def reset_index( | ||
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = None, | ||
drop: bool = False, | ||
inplace: bool = False, | ||
col_level: Hashable = 0, | ||
col_fill: Hashable = "", | ||
*, | ||
drop: bool, | ||
inplace: Literal[True], | ||
col_level: Hashable = ..., | ||
col_fill: Hashable = ..., | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def reset_index( | ||
self, | ||
*, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]], | ||
inplace: Literal[True], | ||
col_level: Hashable = ..., | ||
col_fill: Hashable = ..., | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def reset_index( | ||
self, | ||
*, | ||
inplace: Literal[True], | ||
col_level: Hashable = ..., | ||
col_fill: Hashable = ..., | ||
) -> None: | ||
... | ||
|
||
@overload | ||
def reset_index( | ||
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = ..., | ||
drop: bool = ..., | ||
inplace: bool = ..., | ||
col_level: Hashable = ..., | ||
col_fill: Hashable = ..., | ||
) -> Optional[DataFrame]: | ||
... | ||
|
||
def reset_index( | ||
self, level=None, drop=False, inplace=False, col_level=0, col_fill="" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing the type annotations from the function means that we lose the type checking for the body of the function. so if you reveal_type on say IIUC correctly, the type annotations on the function are used to check the function itself, while the overloads are used when checking other functions that call this one. so both are needed. |
||
): | ||
""" | ||
Reset the index, or a level of it. | ||
|
||
|
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.
Is the last overload needed now? won't it fall back to the function definition if no overloads match?
updated: comment should have been on the next one.
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.
Pretty sure it's needed, see here for a toy example (uncomment the commented-out part and it'll pass)
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.
Commenting out the last overload leads to the same errors observed on
master
in the typing test from #40202 (comment)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.
ah ok, and
Revealed type is 'Any'
. I thought that it fell back to the non-overloaded function with no matching overloads. maybe something changed in mypy or only does so under different conditions.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.
If I've understood correctly, this is it - see #39501 (comment)