Skip to content

Add new --platform flag #2045

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
Aug 23, 2016

Conversation

Michael0x2a
Copy link
Collaborator

@Michael0x2a Michael0x2a commented Aug 23, 2016

This pull request implements #1988 by adding a new --platform flag to allow the user to typecheck code specific to a particular operating system without having to actually run mypy on that OS.

It also modifies the test suite by adding # pyversion: ... and # platform: ... flags to let test suites pick and chose exactly which Python version/OS platform they should run under.

It also adds supports for checks of the form if sys.platform.startswith(...). I added this check mainly because the Python docs seem to explicitly recommend using the startswith idiom over direct comparison.

This adds a new flag allowing you to set what the expected value of
sys.platform is for this particular run. It is similar to the
--python-version flag, which lets you control what the expected value
of sys.version_info for this run is.
Previously, mypy only took into account sys.platform of the form
`sys.platform == ???` or `sys.platform != ???`.

This adds support for `sys.platform.startswith(???)` checks. This will
probably be helpful when writing Python2/Python3-straddling code. For
example, Python 2, sys.platform returns 'linux2' on Linux systems, but
in Python 3, sys.platform will return just 'linux'.
This commit modifies the test suite to allow test cases to set
custom values for the python-version and os-platform flags.
@Michael0x2a
Copy link
Collaborator Author

(This seemed like a useful thing to have implemented before the next Mypy release, mostly for the sake of completeness, so I just went ahead and did it. I'm also not sure if --os-platform is the best name for the flag, so let me know if it I should change it to something else.)

@JukkaL
Copy link
Collaborator

JukkaL commented Aug 23, 2016

What if we'd call it --platform?

@gvanrossum
Copy link
Member

gvanrossum commented Aug 23, 2016 via email

@Michael0x2a Michael0x2a changed the title Add new --os-platform flag Add new --platform flag Aug 23, 2016
@Michael0x2a
Copy link
Collaborator Author

Alright, --platform it is then! I've pushed the change.

@gvanrossum gvanrossum merged commit e602da8 into python:master Aug 23, 2016
@Michael0x2a Michael0x2a deleted the extend-sys-platform-checks branch September 1, 2016 21:04
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.

4 participants