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

Commita29998a

Browse files
authored
gh-116325: RaiseSyntaxError rather thanIndexError on ForwardRef with empty string arg (#116341)
1 parentffcc450 commita29998a

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

‎Lib/test/test_typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,6 +5867,12 @@ def foo(a: 'Node[T'):
58675867
withself.assertRaises(SyntaxError):
58685868
get_type_hints(foo)
58695869

5870+
deftest_syntax_error_empty_string(self):
5871+
forformin [typing.List,typing.Set,typing.Type,typing.Deque]:
5872+
withself.subTest(form=form):
5873+
withself.assertRaises(SyntaxError):
5874+
form['']
5875+
58705876
deftest_name_error(self):
58715877

58725878
deffoo(a:'Noode[T]'):

‎Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ def __init__(self, arg, is_argument=True, module=None, *, is_class=False):
880880
# If we do `def f(*args: *Ts)`, then we'll have `arg = '*Ts'`.
881881
# Unfortunately, this isn't a valid expression on its own, so we
882882
# do the unpacking manually.
883-
ifarg[0]=='*':
883+
ifarg.startswith('*'):
884884
arg_to_compile=f'({arg},)[0]'# E.g. (*Ts,)[0] or (*tuple[int, int],)[0]
885885
else:
886886
arg_to_compile=arg
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`typing`: raise:exc:`SyntaxError` instead of:exc:`AttributeError`
2+
on forward references as empty strings.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp