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

Add test case for global declaration without initializer #6975

Merged
merged 1 commit into from
Jun 13, 2019

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 12, 2019

This crashes on old semantic initializer but doesn't crash when
using the new semantic analyzer. The error message is pretty
poor but that's better than crashing.

Closes #5923.

This crashes on old semantic initializer but doesn't crash when
using the new semantic analyzer.  The error message is pretty
poor but that's better than crashing.

Closes #5923.
@JukkaL JukkaL requested a review from ilevkivskyi June 12, 2019 14:00
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks, looks good, but I have a request for a follow-up issue.

def foo() -> None:
global bar
# TODO: Confusing error message
bar = [] # type: List[str] # E: Name 'bar' already defined (possibly by an import)
Copy link
Member

Choose a reason for hiding this comment

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

I think this deserves an issue. This is kind of a "fundamental" limitation of the new semantic analyzer. So we should give a dedicated error message and explicitly document that users must write something like this:

bar: List[str]
def foo() -> None:
    global bar
    bar = []

Also note that the Python 3.6 version of this test case is a syntax error:

from typing import List

 def foo() -> None:
    global bar
    bar: List[str] = []  # SyntaxError: annotated name 'bar' can't be global

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good points, I'll create a follow-up issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here's the issue: #6976

@JukkaL JukkaL merged commit f8b59b4 into master Jun 13, 2019
@JelleZijlstra JelleZijlstra deleted the semanal-global-crash branch June 13, 2019 16:33
PattenR pushed a commit to PattenR/mypy that referenced this pull request Jun 23, 2019
This crashes on old semantic analyzer but doesn't crash when
using the new semantic analyzer.  The error message is pretty
poor but that's better than crashing.

Closes python#5923.
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.

Crash with global variable
2 participants