Skip to content
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
7 changes: 4 additions & 3 deletions lib/hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def _normalizePath(path):
best = None

for path_entry in sys.path:
if path.startswith(path_entry):
if best is None or len(path_entry) > len(best):
best = path_entry
if path.startswith(path_entry) and (
best is None or len(path_entry) > len(best)
):
best = path_entry
Comment on lines -40 to +43

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _normalizePath refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)


if best is not None:
path = path.replace(best, "$PYTHONPATH")
Expand Down
13 changes: 7 additions & 6 deletions nuitka/Builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _getBuiltinNames():


builtin_names, builtin_warnings = _getBuiltinNames()
builtin_named_values = dict((getattr(builtins, x), x) for x in builtin_names)
builtin_named_values = {getattr(builtins, x): x for x in builtin_names}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 119-119 refactored with the following changes:

  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)

builtin_named_values_list = tuple(builtin_named_values)

assert "__import__" in builtin_names
Expand All @@ -129,11 +129,12 @@ def _getBuiltinNames():


def getBuiltinTypeNames():
result = []
result = [
builtin_name
for builtin_name in builtin_names
if isinstance(getattr(builtins, builtin_name), type)
]

for builtin_name in builtin_names:
if isinstance(getattr(builtins, builtin_name), type):
result.append(builtin_name)
Comment on lines -132 to -136

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getBuiltinTypeNames refactored with the following changes:

  • Convert for loop into list comprehension (list-comprehension)


return tuple(sorted(result))

Expand Down Expand Up @@ -188,7 +189,7 @@ def _getAnonBuiltins():


builtin_anon_names, builtin_anon_codes = _getAnonBuiltins()
builtin_anon_values = dict((b, a) for a, b in builtin_anon_names.items())
builtin_anon_values = {b: a for a, b in builtin_anon_names.items()}
Comment on lines -191 to +192

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 191-191 refactored with the following changes:

  • Replace list(), dict() or set() with comprehension (collection-builtin-to-comprehension)


# For being able to check if it's not hashable, we need something not using
# a hash.
Expand Down
43 changes: 11 additions & 32 deletions nuitka/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ def compareConstants(a, b):
if len(a) != len(b):
return False

for ea, eb in zip(a, b):
if not compareConstants(ea, eb):
return False
return True

return all(compareConstants(ea, eb) for ea, eb in zip(a, b))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function compareConstants refactored with the following changes:

  • Use any() instead of for loop (use-any)
  • Invert any/all to simplify comparisons (invert-any-all)

if type(a) is dict:
if len(a) != len(b):
return False
Expand Down Expand Up @@ -150,19 +146,14 @@ def isConstant(constant):
return False
return True
elif constant_type in (tuple, list):
for element_value in constant:
if not isConstant(element_value):
return False
return True
return all(isConstant(element_value) for element_value in constant)
elif constant_type is slice:
if (
not isConstant(constant.start)
or not isConstant(constant.stop)
or not isConstant(constant.step)
):
return False
return bool(
isConstant(constant.start)
and isConstant(constant.stop)
and isConstant(constant.step)
)

return True
Comment on lines -153 to -165

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function isConstant refactored with the following changes:

  • Simplify conditional into return statement (return-identity)
  • Use any() instead of for loop (use-any)
  • Invert any/all to simplify comparisons (invert-any-all)

elif constant_type in (
str,
unicode,
Expand Down Expand Up @@ -230,15 +221,9 @@ def isMutable(constant):
elif constant_type in (dict, list, set, bytearray):
return True
elif constant_type is tuple:
for value in constant:
if isMutable(value):
return True
return False
return any(isMutable(value) for value in constant)
elif constant_type is frozenset:
for value in constant:
if isMutable(value):
return True
return False
return any(isMutable(value) for value in constant)
Comment on lines -233 to +226

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function isMutable refactored with the following changes:

  • Use any() instead of for loop (use-any)

elif constant is Ellipsis:
return False
elif constant is NotImplemented:
Expand Down Expand Up @@ -277,15 +262,9 @@ def isHashable(constant):
elif constant_type in (dict, list, set, slice, bytearray):
return False
elif constant_type is tuple:
for value in constant:
if not isHashable(value):
return False
return True
return not any(not isHashable(value) for value in constant)
elif constant_type is frozenset:
for value in constant:
if not isHashable(value):
return False
return True
return all(isHashable(value) for value in constant)
Comment on lines -280 to +267

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function isHashable refactored with the following changes:

  • Use any() instead of for loop (use-any)
  • Invert any/all to simplify comparisons (invert-any-all)

elif constant is Ellipsis:
return True
else:
Expand Down
17 changes: 6 additions & 11 deletions nuitka/ModuleRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ def getRootModules():


def hasRootModule(module_name):
for module in root_modules:
if module.getFullName() == module_name:
return True

return False
return any(module.getFullName() == module_name for module in root_modules)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function hasRootModule refactored with the following changes:

  • Use any() instead of for loop (use-any)



def replaceRootModule(old, new):
Expand Down Expand Up @@ -112,12 +108,11 @@ def _normalizeModuleFilename(filename):

def getUncompiledModule(module_name, module_filename):
for uncompiled_module in uncompiled_modules:
if module_name == uncompiled_module.getFullName():
if areSamePaths(
_normalizeModuleFilename(module_filename),
_normalizeModuleFilename(uncompiled_module.filename),
):
return uncompiled_module
if module_name == uncompiled_module.getFullName() and areSamePaths(
_normalizeModuleFilename(module_filename),
_normalizeModuleFilename(uncompiled_module.filename),
):
return uncompiled_module

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getUncompiledModule refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)


return None

Expand Down
24 changes: 9 additions & 15 deletions nuitka/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,45 +226,39 @@ def _splitShellPattern(value):
def getShallFollowInNoCase():
""" *list*, items of "--nofollow-import-to=" / "--recurse-not-to="
"""
return sum([_splitShellPattern(x) for x in options.recurse_not_modules], [])
return sum((_splitShellPattern(x) for x in options.recurse_not_modules), [])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getShallFollowInNoCase refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def getShallFollowModules():
""" *list*, items of "--follow-import-to=" / "--recurse-to="
"""
return sum(
[
_splitShellPattern(x)
for x in options.recurse_modules
+ options.include_modules
+ options.include_packages
],
[],
)
return sum((_splitShellPattern(x) for x in options.recurse_modules
+ options.include_modules
+ options.include_packages), [])
Comment on lines -235 to +237

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getShallFollowModules refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def getShallFollowExtra():
""" *list*, items of "--include-plugin-directory="
"""
return sum([_splitShellPattern(x) for x in options.recurse_extra], [])
return sum((_splitShellPattern(x) for x in options.recurse_extra), [])
Comment on lines -249 to +243

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getShallFollowExtra refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def getShallFollowExtraFilePatterns():
""" *list*, items of "--include-plugin-files="
"""
return sum([_splitShellPattern(x) for x in options.recurse_extra_files], [])
return sum((_splitShellPattern(x) for x in options.recurse_extra_files), [])
Comment on lines -255 to +249

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getShallFollowExtraFilePatterns refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def getMustIncludeModules():
""" *list*, items of "--include-module="
"""
return sum([_splitShellPattern(x) for x in options.include_modules], [])
return sum((_splitShellPattern(x) for x in options.include_modules), [])
Comment on lines -261 to +255

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getMustIncludeModules refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def getMustIncludePackages():
""" *list*, items of "--include-package="
"""
return sum([_splitShellPattern(x) for x in options.include_packages], [])
return sum((_splitShellPattern(x) for x in options.include_packages), [])
Comment on lines -267 to +261

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getMustIncludePackages refactored with the following changes:

  • Replace unneeded comprehension with generator (comprehension-to-generator)



def shallWarnImplicitRaises():
Expand Down Expand Up @@ -372,7 +366,7 @@ def shallUseStaticLibPython():
return (
os.path.exists(os.path.join(sys.prefix, "conda-meta"))
and not Utils.isWin32Windows()
and not Utils.getOS() == "Darwin"
and Utils.getOS() != "Darwin"
Comment on lines -375 to +369

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function shallUseStaticLibPython refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

)


Expand Down
12 changes: 5 additions & 7 deletions nuitka/PythonVersions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ def needsSetLiteralReverseInsertion():


def needsDuplicateArgumentColOffset():
if python_version < 353:
return False
else:
return True
return python_version >= 353

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function needsDuplicateArgumentColOffset refactored with the following changes:

  • Simplify conditional into return statement (return-identity)



def isUninstalledPython():
Expand Down Expand Up @@ -246,9 +243,10 @@ def getPythonABI():
# Cyclic dependency here.
from nuitka.Options import isPythonDebug

if isPythonDebug() or hasattr(sys, "getobjects"):
if not abiflags.startswith("d"):
abiflags = "d" + abiflags
if (
isPythonDebug() or hasattr(sys, "getobjects")
) and not abiflags.startswith("d"):
abiflags = "d" + abiflags

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getPythonABI refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)

else:
abiflags = ""

Expand Down
4 changes: 1 addition & 3 deletions nuitka/SourceCodeReferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def atInternal(self):
it is already internal.
"""
if not self.isInternal():
result = self._clone(self.line)

return result
return self._clone(self.line)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function SourceCodeReference.atInternal refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

else:
return self

Expand Down
13 changes: 7 additions & 6 deletions nuitka/Variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ def addVariableUser(self, user):

# These are not really scopes, just shared uses.
if (
user.isExpressionGeneratorObjectBody()
or user.isExpressionCoroutineObjectBody()
or user.isExpressionAsyncgenObjectBody()
):
if self.owner is user.getParentVariableProvider():
return
(
user.isExpressionGeneratorObjectBody()
or user.isExpressionCoroutineObjectBody()
or user.isExpressionAsyncgenObjectBody()
)
) and self.owner is user.getParentVariableProvider():
return
Comment on lines -124 to +130

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Variable.addVariableUser refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)


self.shared_scopes = True

Expand Down
14 changes: 4 additions & 10 deletions nuitka/__past__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ def iterItems(d):
from urllib import ( # pylint: disable=I0021,import-error,no-name-in-module
urlretrieve,
)
from cStringIO import StringIO # pylint: disable=I0021,import-error
else:
from urllib.request import ( # pylint: disable=I0021,import-error,no-name-in-module
urlretrieve,
)

if str is bytes:
from cStringIO import StringIO # pylint: disable=I0021,import-error
else:
Comment on lines +72 to -79

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 77-79 refactored with the following changes:

  • Merge repeated if statements into single if (merge-repeated-ifs)

from io import StringIO # pylint: disable=I0021,import-error

try:
Expand All @@ -85,7 +83,7 @@ def iterItems(d):
# Lame replacement for functools.total_ordering, which does not exist on
# Python2.6, this requires "<" and "=" and adds all other operations.
def total_ordering(cls):
cls.__ne__ = lambda self, other: not self == other
cls.__ne__ = lambda self, other: self != other
Comment on lines -88 to +86

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function total_ordering refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

cls.__le__ = lambda self, other: self == other or self < other
cls.__gt__ = lambda self, other: self != other and not self < other
cls.__ge__ = lambda self, other: self == other and not self < other
Expand All @@ -98,15 +96,13 @@ def total_ordering(cls):
Iterable,
MutableSet,
)
intern = intern # pylint: disable=I0021,undefined-variable
else:
from collections.abc import ( # pylint: disable=I0021,import-error,no-name-in-module
Iterable, # pylint: disable=I0021,import-error
MutableSet, # pylint: disable=I0021,import-error
)

if str is bytes:
intern = intern # pylint: disable=I0021,undefined-variable
else:
Comment on lines +99 to -109

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 107-109 refactored with the following changes:

  • Merge repeated if statements into single if (merge-repeated-ifs)

intern = sys.intern


Expand All @@ -118,9 +114,7 @@ def getMetaClassBase(meta_class_prefix):
class MetaClass(ABCMeta):
pass

MetaClassBase = MetaClass("%sMetaClassBase" % meta_class_prefix, (object,), {})

return MetaClassBase
return MetaClass("%sMetaClassBase" % meta_class_prefix, (object,), {})
Comment on lines -121 to +117

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function getMetaClassBase refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



# For PyLint to be happy.
Expand Down
9 changes: 6 additions & 3 deletions nuitka/build/SconsInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ def _setupSconsEnvironment():
"""

# For Python2, avoid unicode working directory.
if Utils.isWin32Windows() and python_version < 300:
if os.getcwd() != os.getcwdu():
os.chdir(getWindowsShortPathName(os.getcwdu()))
if (
Utils.isWin32Windows()
and python_version < 300
and os.getcwd() != os.getcwdu()
):
os.chdir(getWindowsShortPathName(os.getcwdu()))
Comment on lines -177 to +182

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function _setupSconsEnvironment refactored with the following changes:

  • Merge nested if conditions (merge-nested-ifs)


if Utils.isWin32Windows():
# On Win32, we use the Python.DLL path for some things. We pass it
Expand Down
20 changes: 7 additions & 13 deletions nuitka/build/inline_copy/appdirs/appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):

WARNING: Do not use this on Windows. See the Vista-Fail note above for why.
"""
if system == "win32":
if system == 'darwin':
path = os.path.expanduser('/Library/Application Support')
if appname:
path = os.path.join(path, appname)
elif system == "win32":
Comment on lines -131 to +135

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function site_data_dir refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Replace if statement with if expression (assign-if-exp)

if appauthor is None:
appauthor = appname
path = os.path.normpath(_get_win_folder("CSIDL_COMMON_APPDATA"))
Expand All @@ -137,10 +141,6 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
path = os.path.join(path, appauthor, appname)
else:
path = os.path.join(path, appname)
elif system == 'darwin':
path = os.path.expanduser('/Library/Application Support')
if appname:
path = os.path.join(path, appname)
else:
# XDG default for $XDG_DATA_DIRS
# only first, if multipath is False
Expand All @@ -152,10 +152,7 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False):
appname = os.path.join(appname, version)
pathlist = [os.sep.join([x, appname]) for x in pathlist]

if multipath:
path = os.pathsep.join(pathlist)
else:
path = pathlist[0]
path = os.pathsep.join(pathlist) if multipath else pathlist[0]
return path

if appname and version:
Expand Down Expand Up @@ -247,10 +244,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False)
appname = os.path.join(appname, version)
pathlist = [os.sep.join([x, appname]) for x in pathlist]

if multipath:
path = os.pathsep.join(pathlist)
else:
path = pathlist[0]
path = os.pathsep.join(pathlist) if multipath else pathlist[0]
Comment on lines -250 to +247

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function site_config_dir refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

return path


Expand Down
Loading