-
-
Notifications
You must be signed in to change notification settings - Fork 128
Fix Union[..., NoneType] injection by get_type_hints if a None default value is used.
#482
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
Changes from 1 commit
376ae56
24c5602
7f000b1
8cc4464
881ffee
58082b9
5c94bd6
b42e203
ed552e4
313ddd8
3ba4ee7
6ffcd23
403e7ce
52c93e9
a1777f3
9e59796
1761a43
54b8eb0
5612f6f
91075ff
1eac721
1f84c68
214dfef
00dedc2
e929085
47e47ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1282,7 +1282,7 @@ def _clean_optional(obj, hints, globalns=None, localns=None): | |
| ): | ||
| continue | ||
| original_value = original_hints[name] | ||
| if original_value is None: # should not happen | ||
| if original_value is None: # should be NoneType already; check just in case | ||
|
||
| original_value = _NoneType | ||
| # Forward reference | ||
| if isinstance(original_value, str): | ||
|
|
@@ -1310,8 +1310,14 @@ def _clean_optional(obj, hints, globalns=None, localns=None): | |
| if sys.version_info < (3, 9) and get_origin(original_evaluated) is Union: | ||
| # Union[str, None, "str"] is not reduced to Union[str, None] | ||
| original_evaluated = Union[original_evaluated.__args__] | ||
| # Compare if values differ | ||
| if original_evaluated != value: | ||
| # Compare if values differ. Note that even if equal | ||
| # value might be cached by typing._tp_cache contrary to original_evaluated | ||
| if original_evaluated != value or ( | ||
| # 3.10: ForwardRefs of UnionType might be turned into _UnionGenericAlias | ||
| hasattr(_types, "UnionType") | ||
| and isinstance(original_evaluated, _types.UnionType) | ||
| and not isinstance(value, _types.UnionType) | ||
| ): | ||
| hints[name] = original_evaluated | ||
|
|
||
| # Python 3.9+ has PEP 593 (Annotated) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.