Proposing __parse__: a standard inverse of __str__
Discussions on Python.org
Proposing __parse__: a standard inverse of __str__
Python standardizes T → str via __str__, but it does not for the partial inverse str ⇀ T. Given a type and a string, nothing in the standard enables introspection whether the type offers string parsing or how to invoke it. A few constructors oblige, but not all of them are useful, like bool("False") yields True. I have drafted a PEP proposing an optional class method, __parse__(cls, text: str, /) -> Self, whose presence is the introspectable, overloadable declaration. It requires no changes to ...
0 comments
No comments yet.