-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
- 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
There was a problem hiding this 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.
docs/source/common_issues.rst
Outdated
@@ -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: |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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.
OK, updated doc and added test. |
A top-level assert has no indentation.
An always-false condition is a check for
sys.platform
orsys.version_info
or a condition derived fromMYPY
or from a namepassed to
--always-false
;assert False
doesn't count (!).(This definition is the same used to exclude conditional imports.)
Fixes #5308.