-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Implement most common sys.version_info and sys.platform checks #1942
Conversation
def is_sys_attr(expr: Node, name: str) -> bool: | ||
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. |
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.
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.
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.
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.
I did a very quick pass and looks reasonable -- I won't have time to review this in detail since I'm going to be on vacation, so please don't wait until you get more feedback :-) A few more ideas for test cases (though at least some of these are probably covered by some existing tests):
|
Thanks for the review! I've added some TODOs and more tests. I'll merge
this once Travis-CI is green.
|
…ion >= (3, 5, 0).
2ae5ef1
to
65cf9ac
Compare
Supporting |
I opened #4661 for this -- but note that we'd need buy-in from PyCharm and Google's pytype as well before we can start using this in stubs (where it's most useful). |
Addresses most but not all of #698. (The first two bullets of my plan.)