Should Python allow reserved keywords as property names?

Okay, out of curiosity I did a quick GitHub search of all keyword_ usages in Python files, which is the canonical way to bypass hard-keyword limitation :grin:

Here are the results (sorted from highest count to lowest count):

Keyword Count Link to search Notes
class_ 158k Link
in_ 99.1k Link Notably used by SQLAlchemy
from_ 89.6k Link 85.5k results with from_ and to (or to_) in the file (link)
or_ 79.6k Link Notably used by SQLAlchemy
assert_ 72.4k Link
and_ 69.6k Link Notably used by SQLAlchemy
is_ 44.8k Link Notably used by SQLAlchemy
lambda_ 32.1k Link
not_ 26.1k Link Notably used by SQLAlchemy
raise_ 23.3k Link
import_ 14.5k Link
else_ 10.6k Link
async_ 10k Link
as_ 9.3k Link
with_ 9.2k Link
if_ 7.3k Link
pass_ 6.8k Link
True_ 6.8k Link
global_ 6.3k Link
return_ 6.1k Link
def_ 5.9k Link
except_ 5k Link
yield_ 3.8k Link
False_ 3.7k Link
continue_ 3.4k Link
for_ 3.2k Link
break_ 2.8k Link
while_ 1.6k Link
await_ 907 Link
elif_ 640 Link
finally_ 414 Link
nonlocal_ 147 Link
try_ 104 Link

So, we can see that from_ is really high in this list, and most of the time indeed in a from/to context.

I don’t know if that’s enough to justify making it special, but I think that show this is a fairly common problem!

4 Likes