-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-85668: Add typing.evaluate_type() function
#150363
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -129,6 +129,7 @@ | |
| 'dataclass_transform', | ||
| 'disjoint_base', | ||
| 'evaluate_forward_ref', | ||
| 'evaluate_type', | ||
| 'final', | ||
| 'get_args', | ||
| 'get_origin', | ||
|
|
@@ -1051,6 +1052,24 @@ def evaluate_forward_ref( | |
| ) | ||
|
|
||
|
|
||
| def evaluate_type( | ||
|
Contributor
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. Should we allow plain strings to be passed, by using |
||
| type_hint, | ||
| *, | ||
| owner=None, | ||
| globalns=None, | ||
| localns=None, | ||
| type_params=None, | ||
| format=None, | ||
| ): | ||
| """Evaluate a type hint, by resolving any forward references. | ||
|
|
||
| This is similar to the evaluate_forward_ref() method, but unlike that method, | ||
| evaluate_type() also supports arbitrary type hints. | ||
| """ | ||
|
|
||
| return _eval_type(type_hint, owner=owner, globalns=globalns, localns=localns, type_params=type_params, format=format) | ||
|
|
||
|
|
||
| def _is_unpacked_typevartuple(x: Any) -> bool: | ||
| # Need to check 'is True' here | ||
| # See: https://github.com/python/cpython/issues/137706 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add :func:`typing.evaluate_type` function. |
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.
We can also properly document the behavior of each argument here, but this will introduce some repetition..