Skip to content
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

gh-116325: Raise SyntaxError on ForwardRef with empty string arg #116341

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Mar 4, 2024

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    typing.Type['']
    ~~~~~~~~~~~^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 389, in inner
    return _caches[func](*args, **kwds)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 1458, in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
             ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 1458, in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
                   ~~~~~~~~~~~^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 187, in _type_check
    arg = _type_convert(arg, module=module, allow_special_forms=allow_special_forms)
          ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 165, in _type_convert
    return ForwardRef(arg, module=module, is_class=allow_special_forms)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/cpython2/Lib/typing.py", line 890, in __init__
    raise SyntaxError(f"Forward reference must be an expression -- got {arg!r}")
SyntaxError: Forward reference must be an expression -- got ''

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another one where I guess it's borderline between a feature and a bug... I don't have a strong opinion either way on whether it should be backported!

@AlexWaygood
Copy link
Member

(Thanks!)

Lib/typing.py Outdated Show resolved Hide resolved
@sobolevn
Copy link
Member Author

sobolevn commented Mar 5, 2024

I don't have a strong opinion either way on whether it should be backported!

I think that it should be. I categorize this as a bug, because IndexError feels out of place here. TypeError is expected, SyntaxError also makes sense.

3.11 still has this bug: https://github.com/python/cpython/blob/3.11/Lib/typing.py#L873

@AlexWaygood AlexWaygood added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Mar 5, 2024
@AlexWaygood AlexWaygood enabled auto-merge (squash) March 5, 2024 08:53
@AlexWaygood AlexWaygood merged commit a29998a into python:main Mar 5, 2024
33 checks passed
@miss-islington-app
Copy link

Thanks @sobolevn for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2024
…ardRef with empty string arg (pythonGH-116341)

(cherry picked from commit a29998a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2024

GH-116347 is a backport of this pull request to the 3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2024
…ardRef with empty string arg (pythonGH-116341)

(cherry picked from commit a29998a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Mar 5, 2024
@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2024

GH-116348 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Mar 5, 2024
sobolevn added a commit that referenced this pull request Mar 5, 2024
…wardRef with empty string arg (GH-116341) (#116347)

gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg (GH-116341)
(cherry picked from commit a29998a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
sobolevn added a commit that referenced this pull request Mar 5, 2024
…wardRef with empty string arg (GH-116341) (#116348)

gh-116325: Raise `SyntaxError` rather than `IndexError` on ForwardRef with empty string arg (GH-116341)
(cherry picked from commit a29998a)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants