Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/python/unicorn/unicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__version__ = "%u.%u.%u" % (__MAJOR, __MINOR, __PATCH)

if _sys.version_info.major == 2:
from .unicorn_py2 import *
else:
if _sys.version_info >= (3,):
Copy link
Contributor

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.

from .unicorn_py3 import *
else:
from .unicorn_py2 import *
7 changes: 3 additions & 4 deletions bindings/python/unicorn/unicorn_py2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,):
Copy link
Contributor

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.

range = xrange

_lib = { 'darwin': 'libunicorn.2.dylib',
Expand Down Expand Up @@ -55,7 +54,7 @@ def _load_win_support(path):
ctypes.cdll.LoadLibrary(lib_file)
#print('SUCCESS')
_loaded_windows_dlls.add(dll)
except OSError as e:
except OSError:
#print('FAIL to load %s' %lib_file, e)
continue

Expand All @@ -72,7 +71,7 @@ def _load_lib(path):
dll = ctypes.cdll.LoadLibrary(lib_file)
#print('SUCCESS')
return dll
except OSError as e:
except OSError:
#print('FAIL to load %s' %lib_file, e)
return None

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/unicorn/unicorn_py3/unicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _load_lib(path: Path, lib_name: str):
# - global load
# - python's lib directory

if sys.version_info.minor >= 12:
if sys.version_info >= (3, 12):
from importlib import resources

canonicals = resources.files('unicorn') / 'lib'
Expand Down
2 changes: 1 addition & 1 deletion tests/regress/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from unicorn.x86_const import *


if sys.version_info.major == 2:
if sys.version_info < (3,):
Copy link
Contributor

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.

range = xrange


Expand Down
Loading