8000 gh-132805: annotationlib: Fix handling of non-constant values in FORWARDREF by JelleZijlstra · Pull Request #132812 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132805: annotationlib: Fix handling of non-constant values in FORWARDREF #132812

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

Merged
merged 15 commits into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apparently trim trailing whitespace was turned off
  • Loading branch information
DavidCEllis committed Apr 22, 2025
commit 97abdc7f44f17d84d248e4f762d5499e5091cbb7
14 changes: 7 additions & 7 deletions Lib/annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def binop(self, other):
def __or__(self, other):
if self.__stringifier_dict__.create_unions:
return types.UnionType[self, other]

return self.__make_new(
ast.BinOp(self.__get_ast(), ast.BitOr(), self.__convert_to_ast(other))
)
Expand Down Expand Up @@ -431,11 +431,11 @@ def rbinop(self, other):
def __ror__(self, other):
if self.__stringifier_dict__.create_unions:
return types.UnionType[other, self]

return self.__make_new(
ast.BinOp(self.__convert_to_ast(other), ast.BitOr(), self.__get_ast())
)

del _make_rbinop

def _make_compare(op):
Expand Down Expand Up @@ -585,10 +585,10 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False):
namespace = {**annotate.__builtins__, **annotate.__globals__}
is_class = isinstance(owner, type)
globals = _StringifierDict(
namespace,
annotate.__globals__,
owner,
is_class,
namespace,
annotate.__globals__,
owner,
is_class,
create_unions=True
)
if annotate.__closure__:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_annotationlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def f(
alpha_anno = anno["alpha"]
self.assertIsInstance(alpha_anno, Union)
self.assertEqual(
typing.get_args(alpha_anno),
typing.get_args(alpha_anno),
(support.EqualToForwardRef("some", owner=f), support.EqualToForwardRef("obj", owner=f))
)

Expand Down
Loading
0