Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1b376b8

Browse files
[3.14] Revert "gh-137969: Fix evaluation ofref.evaluate(format=Format.FORWARDREF) objects (GH-138075) (#140929)" (GH-140931)
Revert "[3.14]gh-137969: Fix evaluation of `ref.evaluate(format=Format.FORWARDREF)` objects (GH-138075) (#140929)"This reverts commitcdb6fe8.
1 parentfa9bb9a commit1b376b8

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

‎Lib/annotationlib.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,19 @@ def evaluate(
159159
type_params=getattr(owner,"__type_params__",None)
160160

161161
# Type parameters exist in their own scope, which is logically
162-
# between the locals and the globals.
163-
type_param_scope= {}
162+
# between the locals and the globals. We simulate this by adding
163+
# them to the globals.
164164
iftype_paramsisnotNone:
165+
globals=dict(globals)
165166
forparamintype_params:
166-
type_param_scope[param.__name__]=param
167-
167+
globals[param.__name__]=param
168168
ifself.__extra_names__:
169169
locals= {**locals,**self.__extra_names__}
170170

171171
arg=self.__forward_arg__
172172
ifarg.isidentifier()andnotkeyword.iskeyword(arg):
173173
ifarginlocals:
174174
returnlocals[arg]
175-
elifargintype_param_scope:
176-
returntype_param_scope[arg]
177175
elifarginglobals:
178176
returnglobals[arg]
179177
elifhasattr(builtins,arg):
@@ -185,15 +183,15 @@ def evaluate(
185183
else:
186184
code=self.__forward_code__
187185
try:
188-
returneval(code,globals=globals,locals={**type_param_scope,**locals})
186+
returneval(code,globals=globals,locals=locals)
189187
exceptException:
190188
ifnotis_forwardref_format:
191189
raise
192190

193191
# All variables, in scoping order, should be checked before
194192
# triggering __missing__ to create a _Stringifier.
195193
new_locals=_StringifierDict(
196-
{**builtins.__dict__,**globals,**type_param_scope,**locals},
194+
{**builtins.__dict__,**globals,**locals},
197195
globals=globals,
198196
owner=owner,
199197
is_class=self.__forward_is_class__,

‎Lib/test/test_annotationlib.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,15 +1911,6 @@ def test_fwdref_invalid_syntax(self):
19111911
withself.assertRaises(SyntaxError):
19121912
fr.evaluate()
19131913

1914-
deftest_re_evaluate_generics(self):
1915-
globalalias
1916-
classC:
1917-
x:alias[int]
1918-
1919-
evaluated=get_annotations(C,format=Format.FORWARDREF)["x"].evaluate(format=Format.FORWARDREF)
1920-
alias=list
1921-
self.assertEqual(evaluated.evaluate(),list[int])
1922-
19231914

19241915
classTestAnnotationLib(unittest.TestCase):
19251916
deftest__all__(self):

‎Misc/NEWS.d/next/Library/2025-08-22-23-50-38.gh-issue-137969.Fkvis3.rst‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp