-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Modify python version check such that linters recognize it #2039
base: dev
Are you sure you want to change the base?
Conversation
Personally I like less the half-tuple comparison (i.e. |
Here's what I'm experiencing: uc = unicorn.Uc(unicorn.UC_ARCH_X86, unicorn.UC_MODE_64)
reveal_type(uc) # Revealed type is "unicorn.unicorn_py2.Uc"mypy(note) Which aligns with what Mypy claims:
|
if _sys.version_info.major == 2: | ||
from .unicorn_py2 import * | ||
else: | ||
if _sys.version_info >= (3,): |
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.
It could make sense if we were differentiating between different minor versions, but only comparing for major version this is less readable.
@@ -23,8 +23,7 @@ | |||
if not hasattr(sys.modules[__name__], "__file__"): | |||
__file__ = inspect.getfile(inspect.currentframe()) | |||
|
|||
_python2 = sys.version_info[0] < 3 | |||
if _python2: | |||
if sys.version_info < (3,): |
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.
This piece of code is redundant altogether. Python 3 never gets here anyway.
@@ -9,7 +9,7 @@ | |||
from unicorn.x86_const import * | |||
|
|||
|
|||
if sys.version_info.major == 2: | |||
if sys.version_info < (3,): |
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.
As mentioned above, this is less readable when comparing major version only.
This is sort of a follow up to #2005. Currently many type checkers have a hard time recognizing all the different ways you can compare versions with
sys.version_info
(it's a best-effort kind of thing).I changed the comparison and made sure that: