Re:Type hinting for Python
by aganders3 on Tuesday January 06, 2015 @11:51AM
(#8845328)
I think I could get over that, but the idea of putting this hinting in comments is troubling for me:
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.
[ Parent
| on HN ]
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.