Skip to content

Skip rest of file upon top-level always-false assert #5894

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 5 commits into from
Nov 15, 2018

Conversation

gvanrossum
Copy link
Member

  • A top-level assert has no indentation.

  • An always-false condition is a check for sys.platform or
    sys.version_info or a condition derived from MYPY or from a name
    passed to --always-false; assert False doesn't count (!).
    (This definition is the same used to exclude conditional imports.)

Fixes #5308.

Guido van Rossum added 3 commits November 14, 2018 15:10
- A top-level assert has no indentation.

- An always-false condition is a check for sys.platform or
  sys.version_info or a condition derived from MYPY or from a name
  passed to --always-false; `assert False` doesn't count (!).

Fixes python#5308
@gvanrossum gvanrossum requested a review from JukkaL November 14, 2018 23:41
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments.

@@ -382,6 +382,22 @@ More specifically, mypy will understand the use of ``sys.version_info`` and
else:
# Other systems

As a special case, you can also use one of these checks in a top-level
``assert``; this makes mypy skip the rest of the file. Example:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe explicitly mention that the assert must be unconditional and not nested within a statement.

@@ -623,3 +623,51 @@ class Child(Parent):
reveal_type(self) # E: Revealed type is '__main__.Child'
return 3
[builtins fixtures/isinstance.pyi]

[case testUnreachableAfterToplevelAssert]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also test the case where the assert is nested within an if statement.

@gvanrossum
Copy link
Member Author

OK, updated doc and added test.

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.

2 participants