8000 Implement most common sys.version_info and sys.platform checks by gvanrossum · Pull Request #1942 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Implement most common sys.version_info and sys.platform checks #1942

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 9 commits into from
Jul 27, 2016
Prev Previous commit
Next Next commit
Add TODOs in response to code review.
  • Loading branch information
Guido van Rossum committed Jul 27, 2016
commit 70bcaea48ca4ee0cfc35b14b7aed7c556afb926d
5 changes: 5 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,8 @@ def consider_sys_platform(expr: Node, platform: str) -> int:
# Cases supported:
# - sys.platform == 'posix'
# - sys.platform != 'win32'
# TODO: Maybe support e.g.:
# - sys.platform.startswith('win')
if not isinstance(expr, ComparisonExpr):
return TRUTH_VALUE_UNKNOWN
# Let's not yet support chained comparisons.
Expand Down Expand Up @@ -2931,6 +2933,9 @@ def contains_sys_version_info(expr: Node) -> Union[None, int, Tuple[Optional[int


def is_sys_attr(expr: Node, name: str) -> bool:
# TODO: This currently doesn't work with code like this:
# - import sys as _sys
# - from sys import version_info
if isinstance(expr, MemberExpr) and expr.name == name:
if isinstance(expr.expr, NameExpr) and expr.expr.name == 'sys':
# TODO: Guard against a local named sys, etc.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this won't work with things like import sys as _sys -- I found 8 files that did this in the Python 2.7 stdlib.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another thing that doesn't work is from sys import platform (which is arguably questionable style and doesn't seem very common). Not sure if we should support it -- one option is to describe it as unsupported in our docs.

Expand Down
0