from Hacker News

PEP 526: Variable declaration in Python

by steinsgate on 8/11/16, 8:13 AM with 82 comments

  • by alanfranzoni on 8/11/16, 10:30 AM

    Bah. If you want a statically typed language, get a statically typed language.

    What's a type hint for if, after that, the user can actually pass a different type?

  • by raverbashing on 8/11/16, 9:40 AM

    Yeah, it seems it's time to abandon Python since the static typing fundamentalists seem to be getting hold of it

    Extremely frustrated by this decision and even though the multiple denials that it won't become a statically typed language it's clear that idea has changed

  • by haney on 8/11/16, 6:45 PM

    I see a ton of comments that are dismissing this but from my experience most code has implicit typing of some sort. This looks like a nice replacement for hand written input validation, if my function expects a number and I pass a string there are 3 options AFAIK:

    1) I have the ability to define a type that's required so that the function can't be called without a numeric type.

    2) I add boiler plate the the top of my function to validate that I'm receiving a number.

    3) I forget to do 1 or 2 and I get a runtime error when a different developer inadvertently passes an incorrect type to my function.

  • by berntb on 8/11/16, 11:08 AM

    Where typing is really useful, in my experience, is in an external API.

    Most heavily used libraries in most dynamic languages, not only Python, ought to have assertions with type checks for parameters. In the external API calls to the lib.

    Inside of a lib you should have tests anyway, so type declarations shouldn't be important.

  • by toyg on 8/11/16, 10:15 AM

    A very sad day. We were told type hints were just that, optional hints to help IDEs and such. Now they're creeping into the language proper; IDEs will start adding them for you, and before you know it all "serious codebases" will be statically typed.

    The beauty of python was that it could read like pseudocode; more and more special characters and notations are putting that idea to rest. I guess it's the price to pay for mainstream success -- when banks get involved, everything becomes uber-formal and soul-crushing.

  • by RodericDay on 8/11/16, 3:56 PM

    Where can we voice our opposition to this?

    If people really want their bulky IDEs to give them maximum help when introspecting a codebase, there should just be a TypeScript like superset of Python that those people can use.

    This syntax is awful and will seriously cause antagonism in terms of what people consider "pythonic" and "good code".

  • by rilut on 8/11/16, 10:17 AM

    Why [T]? Why not <T>? It confuses with array selection
  • by webjunkie on 8/11/16, 9:44 AM

    Why not the other way around:

        my_class_attr = ClassAttr[bool]: True
    
    This seems more familiar somehow.
  • by denfromufa on 8/11/16, 11:44 AM

    I wish mypy, cython, and numba type annotations converge to something common.
  • by w8rbt on 8/11/16, 11:30 AM

    Do the hints increase performance at all? I would think they could.
  • by super_mario on 8/11/16, 11:44 AM

    This is why Python 2.7 will just continue indefinitely.
  • by crdoconnor on 8/11/16, 9:38 AM

    That's a lot of extra character overhead for not very much gain.