-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport annotationlib.value_to_string
#544
Comments
Some suggestions:
|
|
Been looking at this backporting issue and the name discussion. I agree that
So, I'd suggest backporting the function with the name import types
def type_repr(value):
if isinstance(value, type):
if value.__module__ == "builtins":
return value.__qualname__
return f"{value.__module__}.{value.__qualname__}"
if value is ...:
return "..."
if isinstance(value, (types.FunctionType, types.BuiltinFunctionType)):
return value.__name__
return repr(value) Should be pretty straightforward to integrate. Let me know if anything comes up. |
In 3.14, I added a function to
annotationlib
to format type-like values, so you get e.g.int
instead of<type 'int'>
: https://docs.python.org/3.14/library/annotationlib.html#annotationlib.value_to_stringI think this would be useful in typing-extensions too, so let's backport it.
I don't like the name very much though, and it might look even more confusing outside of annotationlib. We can still change it in CPython too, suggestions welcome.
For reference this is what it does:
The text was updated successfully, but these errors were encountered: