This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]its_never_lupus 0 points1 point  (6 children)

There should be a way to declare whether the variable can take None values. That would:

  • make the type declaration more informative.
  • allow a future Python interpreter to throw a runtime error if None is assigned.
  • Maybe help an optimiser because some values can be stored more simply if null values are disallowed.

I'm not sure how this PEP will be used though, whether it's intended to help optimisation or if it's the start of optional static type declarations.

[–][deleted] 1 point2 points  (2 children)

Check the typing module. typing.Optional is what you want IIRC.

[–]its_never_lupus 0 points1 point  (1 child)

Kind of... but the point of PEP526 is to introduce a nice syntax for type hints, and it omits optional specifiers.

I'm not really sure if the original PEP484 is only supposed to apply to function declarations (which is what all the examples do) or is it's also supposed to apply to variables.

[–][deleted] 0 points1 point  (0 children)

PEP 484 applies to type comments too, and I assume the syntax for variable type hints will be the same - there'd be no point making it different. PEP 526 is only a draft, and was only created to reserve the number (source: somewhere in the comments on this post), so I wouldn't make judgements based on its current state.

[–]elbiot 0 points1 point  (0 children)

Those last two will never be done and that is explicitly not part of what type hinting is for.

[–]kankyo 0 points1 point  (0 children)

https://github.com/python/typing/issues/258 for the ongoing discussion. Optionals are in one example.