Uncategorized

Should Python allow reserved keywords as property names? – Ideas


Yeah, it’s not a hard indicator, but it does help. Ultimately, the important thing is to figure out unambiguously whether it’s to be a keyword or an identifier.

The case for the current set of soft keywords is the opposite of the OP.

Soft keywords were introduced because making them hard (recognized by the tokenizer) would have broken too much existing code.

So are you proposing to make from soft?

Side note: the only problem I have with keywords is with class, and I use klass, not class_. I never use underscores at the end of a name, I find it unreadable and ugly. IMHO.

I never had problems with from, but probably instead of using from I’ll use origin, or start, or begin, or something else.

Out of interest, how many people here prefer klass, how many prefer class_, and how many prefer cls? I’m in the third camp, myself.

These serve different roles:
cls is the preferred spelling for a class instance, in class methods for example
class_ (similar to from_), a way to name something that’s not a python class (like an HTML class)
klass (or frm) is an ugly form, hard to read and not recommended by PEP 8



1 Like

I was thinking about it, but I think this discussion made clear that even if the need to name things “from” is really common, making it a soft keywod is not as simple as I thought (I totally forgot about yield from and raise from too!), and probably a bad idea overall.



1 Like

If make keywords soft, how is the compiler expected to interpret expression “not and - 1”?

This kind of stuff is why I only would argue for soft keywords that are not part of expressions, e.g. class, def, match/case are fine, but not and and aren’t. I thought from was fine because I forgot about yield from.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *