Skip to content

feat: reachability recognizes platform.system() #10686

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

atakiar
Copy link
Contributor

@atakiar atakiar commented Jun 21, 2021

Description

As title. Closes #8166. See PRs #8461 and python/typeshed#5671 for context

Test Plan

Duplicated all existing sys.platform test cases (minus the one that tests for sys.platform.startswith) and added several to ensure a valid mapping of sys.platform to platform.system()

@atakiar
Copy link
Contributor Author

atakiar commented Jun 21, 2021

It's worth calling out that we don't add platform.system() to options (see comments on #8461) and use its value directly. Instead, we map sys.platform to platform.system(). This mapping isn't perfect and mypy behavior is not exactly the same between the two. Consider the following:

[case testUnreachableAfterToplevelAssertImport2]
# flags: --platform lol
import foo
foo.bar()  # No error

[file foo.py]
import sys
assert sys.platform == 'lol' # mypy sees this as ALWAYS_TRUE
def bar() -> None: pass
[case testUnreachableAfterToplevelAssertImport4]
# flags: --platform lol
import foo
foo.bar()  # No error

[file foo.py]
import platform
assert platform.system() == 'lol' # mypy sees this as TRUTH_VALUE_UNKNOWN
def bar() -> None: pass

@Akuli
Copy link
Contributor

Akuli commented Jun 22, 2021

Note for reviewers: Instead of hard-coding platform.system() and a mapping of values in mypy (this pr), we could change how equality checks with literals work, and it might help other type checkers too (python/typeshed#5671).

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

urllib3 (https://github.com/urllib3/urllib3)
+ test/conftest.py:28: error: Unused "type: ignore" comment

pytest (https://github.com/pytest-dev/pytest.git)
+ src/_pytest/doctest.py:302: error: Statement is unreachable  [unreachable]

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.

Recognize platform.system() as well as sys.platform
3 participants