Hacker News new | past | comments | ask | show | jobs | submit login

I think I could get over that, but the idea of putting this hinting in comments is troubling for me:

    x = {}    # type: Dict[str, str]
I mean, it's very human-readable so it makes sense as a comment. It's optional, so not every declaration will have it. Still, something about the interpreter reading my comments is off-putting.



Yeah, that gives me the heebie jeebies. Fair enough if you want to use magic comments for an entirely third-party system like MyPy, but using them for a built-in language feature feels wrong.

Besides, how necessary is it? Presumably those constrained types can be instantiated:

    x = Dict[str, str]()
The constrained type's __new__ would be annotated appropriately, and return an ordinary dict. It's a bit less "pure" in that this is no longer strictly an annotation, but I'd much prefer that bit of impurity than magic comments.


Agreed. It seems like a simple typo e.g.

    x = {}  # tyep: Dict[str, str]
is a recipe for spending 6 hours wondering why you've got integers in your string-only dict.

(Assuming the interpreter ignores anything not matching `# type:`


Truly terrifying: I had to read your comment four times before I could find the typo.


Yeah, something like

    x: dict<str, str> = {}
would be nicer, I think.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: