Skip to content

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.

# 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.

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