Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How to specify constants of type NoneType? #2

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
matthiaskramm opened this issue Mar 12, 2015 · 6 comments
Closed

How to specify constants of type NoneType? #2

matthiaskramm opened this issue Mar 12, 2015 · 6 comments

Comments

@matthiaskramm
Copy link
Contributor

PEP 484 says "By default, None is an invalid value for any type". However, in the Python standard library there are class-level and module-level constants that are legitimately None.

Examples:

  formatter.py.AS_IS
  hmac.digest_size
  cgi.FieldStorage.FieldStorageClass
  copy.PyStringMap

Should we allow these to be declared using e.g. something like

  AS_IS = Undefined(NoneType)

?

@vlasovskikh
Copy link
Member

The variables could be of their concrete type or of an optional concrete type depending on whether it is desirable to have the check for None enabled for them.

For example, a PEP 484 compatible definition of hmac.digest_size could look like this:

digest_size = ...  # type: int

or like this:

digest_size = ... # type: Optional[int]

@gvanrossum
Copy link
Member

Maybe one of the following should be declared best practice?

foo = None  # type: object
foo = None  # type: Optional[object]

All of these work today with mypy.

@matthiaskramm
Copy link
Contributor Author

What about

foo = None  # type: None

It doesn't work in mypy yet, but mypy's error message sounds like it could, in the future.

@gvanrossum
Copy link
Member

gvanrossum commented Jan 27, 2016 via email

momandine pushed a commit to momandine/typeshed that referenced this issue Jul 5, 2016
momandine pushed a commit to momandine/typeshed that referenced this issue Jul 5, 2016
@gvanrossum
Copy link
Member

This is almost(ish :-) over. With --strict-optional, mypy does not complain about

x = None # type: None

We'll just have to finish for the strict None checking flag in mypy to become the default.

rowillia added a commit to rowillia/typeshed that referenced this issue Dec 29, 2016
rowillia added a commit to rowillia/typeshed that referenced this issue Jan 11, 2017
rowillia added a commit to rowillia/typeshed that referenced this issue Jan 12, 2017
JelleZijlstra added a commit to JelleZijlstra/typeshed that referenced this issue Apr 23, 2017
@JelleZijlstra
Copy link
Member

x = None # type: None works fine in mypy with python/mypy#3024 merged.

I'm submitting a PR to fix the specific objects @matthiaskramm mentioned.

ambv pushed a commit that referenced this issue Apr 24, 2017
cocoatomo pushed a commit to cocoatomo/typeshed that referenced this issue Jul 16, 2018
hatal175 added a commit to hatal175/typeshed that referenced this issue Apr 8, 2021
Co-authored-by: Sebastian Rittau <[email protected]>
AlexWaygood referenced this issue in AlexWaygood/typeshed Dec 6, 2021
amaslenn added a commit to amaslenn/typeshed that referenced this issue Oct 16, 2022
amaslenn added a commit to amaslenn/typeshed that referenced this issue Oct 28, 2022
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

No branches or pull requests

4 participants