3 ms·
Why not the other way around: my_class_attr = ClassAttr[bool]: True This seems more familiar somehow.
by webjunkie 10y ago
Why not the other way around:
my_class_attr = ClassAttr[bool]: True
This seems more familiar somehow.
- talideon 10y agoA few reasons, not least of which is consistency with function/method signature declarations. Also, that style is only more familiar if you're coming from C, C++, Java, &c. However, the style in the PEP is pretty common in languages outside of the C family, such as those inspired by Pascal, and there's at least two examples of C family languages - Go and Swift - which use the style in the PEP. Also, putting the declaration on the LHS likely results in fewer grammar ambiguities, but it's well over a decade since I last looked at Python's grammar, so that's just speculation on my part. I know that's one of the reasons why Swift and Go went down the route they did, and Python would have even more reason, given how ':' is used in the language.