Live data from Hacker News

PEP 0484 – Type Hints is accepted

python.org

11–20 of 75 posts

Re: PEP 0484 – Type Hints is accepted

#11
post #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.

It really is. Since using Haskell, the type systems in the mainstream languages I've used have seemed sorely lacking.

Re: PEP 0484 – Type Hints is accepted

#12

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.

Yeah, isn't that amazing? I really think this "type" idea is a good one. I wonder if other languages have thought about following Python's lead and adding a type system.

Re: PEP 0484 – Type Hints is accepted

#13

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

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

Don't forget Javascript, via Typescript (which predates both Python and PHP's typechecking): http://www.typescriptlang.org/

Typescript is a strict superset of Javascript that compiles very transparently to the equivalent Javascript, so I think it's close enough to what Python3 does to be included here.

The annotations are stripped out before runtime, but they are checked at compile-time for any errors that are possible to detect statically.

Re: PEP 0484 – Type Hints is accepted

#14
post #12

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.

Yeah, isn't that amazing? I really think this "type" idea is a good one. I wonder if other languages have thought about following Python's lead and adding a type system.

Would you like to reconsider your tone?

Re: PEP 0484 – Type Hints is accepted

#15

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.

Thanks for the link. I developed the annotation+decorator-based type checker in https://github.com/kislyuk/ensure before I saw typecheck-decorator (which looks like it has some cool features). One thing I'm proud of with ensure's @ensure_annotations decorator is that we actually went through a few rounds of optimization and are fairly confident in the decorator's runtime performance.

Optional type checking as a first-class citizen is a great tool to have, and it's good to see the syntax standardized.

But as alluded to in the Reddit thread, there are serious issues with this PEP. The use of comments and the lack of runtime type checking from the start not only limits the potential of this particular PEP, but undermines future efforts to bring that functionality in.

IMO it would have been better to put in the work and properly integrate type checking decorations into the interpreter and the grammar. The tack-on comments at the end of the line are especially un-Pythonic and jarring.

Edit: Just saw the string literal based forward references. Ugh. Another problem in the making.

Re: PEP 0484 – Type Hints is accepted

#16

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

> So now two popular dynamic languages have type hinting of a kind: Python (unenforced annotations) and PHP (declarations). Great! Don't forget Javascript, via Typescript (which predates both Python and PHP's typechecking): http://www.typescriptlang.org/ Typescript is a strict superset of Javascript that compiles very transparently to the equivalent Javascript, so I think it's close enough to what Python3 does to be…

And Dart - which had optional types from the start.

Re: PEP 0484 – Type Hints is accepted

#18
post #14
post #12

Earlier quoted context omitted.

Yeah, isn't that amazing? I really think this "type" idea is a good one. I wonder if other languages have thought about following Python's lead and adding a type system.

Would you like to reconsider your tone?

No, but let me clarify. Bolting on a form of type checking to a weakly typed language seems orthogonal to the nature of a language like Python. If you find yourself saying "I wish I had a type system in this code base, its getting pretty big and a compiler that does type checking at compile time sure would make my life easier" maybe you should think about using a more appropriate tool.

I use Python a lot and it has its uses, but adding this type hint stuff just seems like an enabler for causing myself pain and denial when I should be using a more strongly typed language.

Re: PEP 0484 – Type Hints is accepted

#19

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

> So now two popular dynamic languages have type hinting of a kind: Python (unenforced annotations) and PHP (declarations). Great! Don't forget Javascript, via Typescript (which predates both Python and PHP's typechecking): http://www.typescriptlang.org/ Typescript is a strict superset of Javascript that compiles very transparently to the equivalent Javascript, so I think it's close enough to what Python3 does to be…

TypeScript is a JS superset, though. It's not part of JS itself.

Re: PEP 0484 – Type Hints is accepted

#20

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.

This might sound odd, but lately I haven't noticed any bugs I've introduced to production that were type errors.

Inevitably my code will produce results of the right type, but have a logical error that makes either the answer flat out wrong or more or less inaccurate based on our cloud requirements.

Post reply on HN