Skip to content
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

Reconsider "not None" versus "or None" for typed object arguments #2696

Closed
scoder opened this issue Nov 1, 2018 · 3 comments
Closed

Reconsider "not None" versus "or None" for typed object arguments #2696

scoder opened this issue Nov 1, 2018 · 3 comments

Comments

@scoder
Copy link
Contributor

scoder commented Nov 1, 2018

We had discussions at some point about switching from the opt-out "not None" qualifier for object typed function arguments to an opt-in "or None". The rational is that people tend to forget more often than not that None is a valid argument value, and fail to guard their code against it. This also applies to memory views and buffer arguments. Rejecting None and allowing it optionally might be a safer default behaviour.

However, the current default is also the normal Python behaviour. And this feature would then also have to be available in pure Python mode somehow, where None is always a valid value. Both might count as arguments for not changing the behaviour.

@robertwb
Copy link
Contributor

robertwb commented Nov 3, 2018 via email

@scoder
Copy link
Contributor Author

scoder commented Apr 23, 2020

I'm rejecting this idea for the reasons given above. It's not obvious that changing it to or None would make it better overall, and it comes with its own set of drawbacks.

@scoder
Copy link
Contributor Author

scoder commented Jan 29, 2022

This has now been implemented as part of #3400 / #2903 when Python type annotations are used. When types are provided in Python syntax, we apply standard Python typing semantics that require Optional[...] when None is allowed. Since such code is either Python code or newly written Cython code, this avoids a major issue with backwards incompatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants