Skip to content

FEATURE: Start using Never as return types for disallowed operations #441

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

Closed
Dr-Irv opened this issue Nov 23, 2022 · 2 comments · Fixed by #506
Closed

FEATURE: Start using Never as return types for disallowed operations #441

Dr-Irv opened this issue Nov 23, 2022 · 2 comments · Fixed by #506

Comments

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Nov 23, 2022

See #432 where methods were added to TimestampSeries and TimedeltaSeries that return Never, which pyright will pick up as invalid.

We could add more of these to disallow certain operations between incompatible types, and then use the TYPE_CHECKING_INVALID_USAGE pattern to check for these.

@twoertwein
Copy link
Member

Or NoReturn PyCQA/flake8-pyi#272

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 11, 2023

Turns out that we should not do this. See discussion here:
python/mypy#14424

If you have a base class Base and a subclass Sub, then just declare the valid parameters for a method in Sub. This will override any declaration in Base. For mypy, probably need # type: ignore[override].

If you have a method xyz(self, x: Any) in Base and you don't want to allow Sub to be called then add def xyz(self, x: Never) -> Never in Sub, or in Sub, you can write xyz = None.

@Dr-Irv Dr-Irv mentioned this issue Jan 11, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants