| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -242,21 +242,10 @@ def _type_repr(obj): | |
| typically enough to uniquely identify a type. For everything | ||
| else, we fall back on repr(obj). | ||
| """ | ||
| # When changing this function, don't forget about | ||
| # `_collections_abc._type_repr`, which does the same thing | ||
| # and must be consistent with this one. | ||
| if isinstance(obj, type): | ||
| if obj.__module__ == 'builtins': | ||
| return obj.__qualname__ | ||
| return f'{obj.__module__}.{obj.__qualname__}' | ||
| if obj is ...: | ||
| return '...' | ||
| if isinstance(obj, types.FunctionType): | ||
| return obj.__name__ | ||
| if isinstance(obj, tuple): | ||
| # Special case for `repr` of types with `ParamSpec`: | ||
| return '[' + ', '.join(_type_repr(t) for t in obj) + ']' | ||
|
Comment thread
Comment on lines
245
to
247
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is a case we don't want in value_to_source?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes, I think it's specifically for the internals of Callable and doesn't make sense in general. (Notice that it represents tuples with list syntax.)
Sorry, something went wrong.
All reactions
|
||
| return repr(obj) | ||
| return annotationlib.value_to_source(obj) | ||
|
|
||
|
|
||
| def _collect_type_parameters(args, *, enforce_default_ordering: bool = True): | ||
| Expand Down Expand Up | @@ -2948,14 +2937,10 @@ def annotate(format): | |
| if format in (annotationlib.Format.VALUE, annotationlib.Format.FORWARDREF): | ||
| return checked_types | ||
| else: | ||
| return _convert_to_source(types) | ||
| return annotationlib.annotations_to_source(types) | ||
| return annotate | ||
|
|
||
|
|
||
| def _convert_to_source(types): | ||
| return {n: t if isinstance(t, str) else _type_repr(t) for n, t in types.items()} | ||
|
|
||
|
|
||
| # attributes prohibited to set in NamedTuple class syntax | ||
| _prohibited = frozenset({'__new__', '__init__', '__slots__', '__getnewargs__', | ||
| '_fields', '_field_defaults', | ||
| Expand Down Expand Up | @@ -3241,7 +3226,7 @@ def __annotate__(format): | |
| for n, tp in own.items() | ||
| } | ||
| elif format == annotationlib.Format.SOURCE: | ||
| own = _convert_to_source(own_annotations) | ||
| own = annotationlib.annotations_to_source(own_annotations) | ||
| else: | ||
| own = own_checked_annotations | ||
| annos.update(own) | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality"approximately the SOURCE format" 😆
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.