| 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 | @@ -461,7 +461,7 @@ class Starship: | |
| be used with isinstance() or issubclass(). | ||
| """ | ||
| item = _type_check(parameters, f'{self} accepts only single type.') | ||
| return _GenericAlias(self, (item,), name="ClassVar") | ||
| return _GenericAlias(self, (item,)) | ||
|
|
||
| @_SpecialForm | ||
| def Final(self, parameters): | ||
| Expand All | @@ -482,7 +482,7 @@ class FastConnector(Connection): | |
| There is no runtime checking of these properties. | ||
| """ | ||
| item = _type_check(parameters, f'{self} accepts only single type.') | ||
| return _GenericAlias(self, (item,), name="Final") | ||
| return _GenericAlias(self, (item,)) | ||
|
|
||
| @_SpecialForm | ||
| def Union(self, parameters): | ||
| Expand Down Expand Up | @@ -520,12 +520,9 @@ def Union(self, parameters): | |
| parameters = _remove_dups_flatten(parameters) | ||
| if len(parameters) == 1: | ||
| return parameters[0] | ||
|
|
||
| if len(parameters) == 2 and type(None) in parameters: | ||
| name = "Optional" | ||
| else: | ||
| name = "Union" | ||
| return _UnionGenericAlias(self, parameters, name=name) | ||
| return _UnionGenericAlias(self, parameters, name="Optional") | ||
| return _UnionGenericAlias(self, parameters) | ||
|
|
||
| @_SpecialForm | ||
| def Optional(self, parameters): | ||
| Expand Down Expand Up | @@ -570,7 +567,7 @@ def open_helper(file: str, mode: MODE) -> str: | |
| except TypeError: # unhashable parameters | ||
| pass | ||
|
|
||
| return _LiteralGenericAlias(self, parameters, name="Literal") | ||
| return _LiteralGenericAlias(self, parameters) | ||
|
|
||
|
|
||
| @_SpecialForm | ||
| Expand Down Expand Up | @@ -609,7 +606,7 @@ def Concatenate(self, parameters): | |
| "ParamSpec variable.") | ||
| msg = "Concatenate[arg, ...]: each arg must be a type." | ||
| parameters = tuple(_type_check(p, msg) for p in parameters) | ||
| return _ConcatenateGenericAlias(self, parameters, name="Concatenate") | ||
| return _ConcatenateGenericAlias(self, parameters) | ||
|
|
||
|
|
||
| @_SpecialForm | ||
| Expand Down Expand Up | @@ -657,7 +654,7 @@ def is_str(val: Union[str, float]): | |
| PEP 647 (User-Defined Type Guards). | ||
| """ | ||
| item = _type_check(parameters, f'{self} accepts only single type.') | ||
| return _GenericAlias(self, (item,), name="TypeGuard") | ||
| return _GenericAlias(self, (item,)) | ||
|
|
||
|
|
||
| class ForwardRef(_Final, _root=True): | ||
| Expand Down Expand Up | @@ -962,7 +959,7 @@ def __mro_entries__(self, bases): | |
|
|
||
| def __getattr__(self, attr): | ||
| if attr in {'__name__', '__qualname__'}: | ||
| return self._name | ||
| return self._name or self.__origin__.__name__ | ||
|
Comment thread
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 solution is so nice. I wish I'd thought about this a little deeper when I proposed the original one:(. Anyways if I'm not wrong, __origin__ will always be set on all GenericAlias to some type, so this should always succeed.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| # We are careful for copy and pickle. | ||
| # Also for simplicity we just don't relay all dunder names | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
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 QualityWill there be a subtle difference between how the two behaves since one sets name and the other doesn't?
I would think not but I'm not sure.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 QualitySetting _name affects subclassing and pickling/copying. Union[] and Optional[] are not subclassable, and special implementation of __reduce__ was added in previous commits. If there are other difference, I do not know.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.