-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: annotate functions that always error with NoReturn #48002
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
Conversation
@@ -1243,7 +1244,7 @@ def groupings(self) -> list[grouper.Grouping]: | |||
ping = grouper.Grouping(lev, lev, in_axis=False, level=None) | |||
return [ping] | |||
|
|||
def _aggregate_series_fast(self, obj: Series, func: Callable) -> np.ndarray: | |||
def _aggregate_series_fast(self, obj: Series, func: Callable) -> NoReturn: |
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.
When we have NotImplementedError
, does the NoReturn
not create issues with subtypes? (in general, no checked this particular case)
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.
Yes it would create issues with sub-types that actually implement these functions. Parent methods should probably be abstract with a signature that the child will implement.
It should be safe adding NoReturn
to final
methods as no child class is meant to implement them. Based on the doc-string of _aggregate_series_fast
I assume this method is basically deprecated and is not implemented in sub-classes.
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.
Thanks. yes it does appear that the exception is not for public consumption.
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.
NoReturn is useful in cases like this to narrow the type:
def error() -> NoReturn: ...
def test(x: int | str) -> str:
# x: int | str
if isinstance(x, int):
error()
# x: str
return x + "some_string"
I don't there are many places where NoReturn can be used in pandas, in most cases we should make classes abstract.
Is there a historic reason to avoid inheriting from ABC
and using abstractmethod
? Happy to make PRs to make more methods abstract.
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.
Thanks @twoertwein lgtm apart from general question on generic usage of NoReturn
Thanks @twoertwein |
There are more non-abstract functions that also error. Most of them should probably be abstract functions. I ignored those functions.