Live data from Hacker News

PEP 0484 – Type Hints is accepted

python.org

1–10 of 75 posts

Re: PEP 0484 – Type Hints is accepted

#4

This seems exciting. I'm not familiar with the availability of new Python features. When can I use this in my day to day Python?

https://github.com/JukkaL/mypy is the/one implementation of a static checker that conforms to PEP 484. (Naturally, as far as I know, JukkaL with mypy almost singlehandedly inspired the PEP.)

Re: PEP 0484 – Type Hints is accepted

#6

This seems exciting. I'm not familiar with the availability of new Python features. When can I use this in my day to day Python?

You can use it today if you want to, there is already language support for adding your own type notation.

And if you don't want to create your own you could use https://pypi.python.org/pypi/obiwan

Re: PEP 0484 – Type Hints is accepted

#7

This seems exciting. I'm not familiar with the availability of new Python features. When can I use this in my day to day Python?

Simple function annotations like

  def foo(x: int) -> str: ...
have been available since 3.0, and editors like PyCharm already use them for typechecking.

For new PEP 0484 features like generics, MyPy supports Python 3.2 and up, but PyCharm support seems to be work in progress: https://youtrack.jetbrains.com/issue/PY-15206

Re: PEP 0484 – Type Hints is accepted

#9

So now two popular dynamic languages have type hinting of a kind: Python (unenforced annotations) and PHP (declarations). Great!

I encourage all use of the type system to ensure program correctness, but once you've had Hindley-Milner inference, it's hard to muddle along with something like this.

Re: PEP 0484 – Type Hints is accepted

#10
One of the reasons why I use Python 3.x exclusively is for the new function annotations, which allow use of this: https://github.com/prechelt/typecheck-decorator

This allows me to write Python in a design-by-contract style with full, rich runtime type checks. My bug count has gone down dramatically, and when I do find a bug it's virtually always via a typecheck exception.

Post reply on HN