4 ms·
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 hu
by aganders3 12y ago
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.
- temuze 12y agoYeah, something like x: dict<str, str> = {} would be nicer, I think.
- deleted 12y ago[deleted]
- suvelx 12y agoAgreed. 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:`
- aganders3 12y agoTruly terrifying: I had to read your comment four times before I could find the typo.
- alexhill 12y agoYeah, 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.