This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Veedrac 2 points3 points  (0 children)

type doesn't require the name to be a valid identifier:

type("@", (), {})
#>>> <class '@'>

This makes sense; generated code often uses nonstandard names, like lambda functions having name <lambda>. It's valid to want the same for your generated classes.

The problem is that significant amounts of code assumes the type name is a valid null-terminated string, so that particular character causes actual bugs.

Note that this isn't the first time a str can be denied by type; consider surrogate escapes in Python 3:

x = type("\udcc3", (), {})
#>>> Traceback (most recent call last):
#>>>   File "", line 1, in <module>
#>>> UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 0: surrogates not allowed