Sourcery refactored develop branch#1
Conversation
| ) | ||
| for res in args: | ||
| yield res | ||
| yield from args |
There was a problem hiding this comment.
Function get_args refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from)
| script_text = runner_script_template | ||
| for group in "console_scripts", "gui_scripts": | ||
| for name, _ep in dist.get_entry_map(group).items(): | ||
| script_text = runner_script_template |
There was a problem hiding this comment.
Function get_script_args refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop)
| 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 |
There was a problem hiding this comment.
Function _normalizePath refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
|
|
||
| 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} |
There was a problem hiding this comment.
Lines 119-119 refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| 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) |
There was a problem hiding this comment.
Function getBuiltinTypeNames refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| return sum([_splitShellPattern(x) for x in options.recurse_extra_files], []) | ||
| return sum((_splitShellPattern(x) for x in options.recurse_extra_files), []) |
There was a problem hiding this comment.
Function getShallFollowExtraFilePatterns refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| return sum([_splitShellPattern(x) for x in options.include_modules], []) | ||
| return sum((_splitShellPattern(x) for x in options.include_modules), []) |
There was a problem hiding this comment.
Function getMustIncludeModules refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| return sum([_splitShellPattern(x) for x in options.include_packages], []) | ||
| return sum((_splitShellPattern(x) for x in options.include_packages), []) |
There was a problem hiding this comment.
Function getMustIncludePackages refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| and not Utils.getOS() == "Darwin" | ||
| and Utils.getOS() != "Darwin" |
There was a problem hiding this comment.
Function shallUseStaticLibPython refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| return False | ||
| else: | ||
| return True | ||
| return python_version >= 353 |
There was a problem hiding this comment.
Function needsDuplicateArgumentColOffset refactored with the following changes:
- Simplify conditional into return statement (
return-identity)
| if ( | ||
| isPythonDebug() or hasattr(sys, "getobjects") | ||
| ) and not abiflags.startswith("d"): | ||
| abiflags = "d" + abiflags |
There was a problem hiding this comment.
Function getPythonABI refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| result = self._clone(self.line) | ||
|
|
||
| return result | ||
| return self._clone(self.line) |
There was a problem hiding this comment.
Function SourceCodeReference.atInternal refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| 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 |
There was a problem hiding this comment.
Function Variable.addVariableUser refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs)
| 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: |
There was a problem hiding this comment.
Lines 77-79 refactored with the following changes:
- Merge repeated if statements into single if (
merge-repeated-ifs)
| cls.__ne__ = lambda self, other: not self == other | ||
| cls.__ne__ = lambda self, other: self != other |
There was a problem hiding this comment.
Function total_ordering refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if is_String(c) and not '\n' in c: | ||
| if is_String(c) and '\n' not in c: |
There was a problem hiding this comment.
Function LazyAction.get_parent_class refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if env: | ||
| c = env.get(self.var, '') | ||
| else: | ||
| c = '' | ||
| c = env.get(self.var, '') if env else '' |
There was a problem hiding this comment.
Function LazyAction._generate_cache refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| action = Action(ac, strfunction=ac.strfunction) | ||
| return action | ||
| return Action(ac, strfunction=ac.strfunction) |
There was a problem hiding this comment.
Function ActionFactory.__call__ refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| matchsuf = [S for S in suffixes if path[-len(S):] == S] | ||
| if matchsuf: | ||
| suf = max([(len(_f),_f) for _f in matchsuf])[1] | ||
| suf = max((len(_f),_f) for _f in matchsuf)[1] |
There was a problem hiding this comment.
Function match_splitext refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| result = BuilderBase(**kw) | ||
|
|
||
| if not composite is None: | ||
| if composite is not None: |
There was a problem hiding this comment.
Function Builder refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| raise UserError("Multiple ways to build the same target were specified for: %s" % t) | ||
| if t.has_explicit_builder(): | ||
| if not t.env is None and not t.env is env: | ||
| if t.env is not None and t.env is not env: |
There was a problem hiding this comment.
Function _node_errors refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs) - Simplify logical expression using De Morgan identities (
de-morgan)
| if not chdir is _null: | ||
| if chdir is not _null: |
There was a problem hiding this comment.
Function BuilderBase.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if env: | ||
| suffixes = self.src_suffixes(env) | ||
| else: | ||
| suffixes = [] | ||
| suffixes = self.src_suffixes(env) if env else [] |
There was a problem hiding this comment.
Function BuilderBase.splitext refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if suff and not suff[0] in [ '.', '_', '$' ]: | ||
| if suff and suff[0] not in ['.', '_', '$']: |
There was a problem hiding this comment.
Function BuilderBase.adjust_suffix refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
|
|
||
| def is_enabled(self): | ||
| return (cache_enabled and not self.path is None) | ||
| return cache_enabled and self.path is not None |
There was a problem hiding this comment.
Function CacheDir.is_enabled refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| if platform is None: | ||
| platform = SCons.Platform.Platform() | ||
| if platform is None: | ||
| platform = SCons.Platform.Platform() |
There was a problem hiding this comment.
Function Base.__init__ refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if) - Replace assignment with augmented assignment (
aug-assign)
| self._dict[key] = dk + val | ||
| else: | ||
| dk = [x for x in dk if x not in val] | ||
| self._dict[key] = dk + val | ||
| self._dict[key] = dk + val |
There was a problem hiding this comment.
Function Base.AppendUnique refactored with the following changes:
- Hoist repeated code outside conditional statement (
hoist-statement-from-if) - Replace if statement with if expression (
assign-if-exp) - Simplify logical expression using De Morgan identities (
de-morgan)
| if key: | ||
| dict = self.Dictionary(key) | ||
| else: | ||
| dict = self.Dictionary() | ||
| dict = self.Dictionary(key) if key else self.Dictionary() |
There was a problem hiding this comment.
Function Base.Dump refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if not val in dk: | ||
| if val not in dk: |
There was a problem hiding this comment.
Function Base.PrependUnique refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| for executor in uniq.keys(): | ||
| for executor in uniq: |
There was a problem hiding this comment.
Function Base.AddPreAction refactored with the following changes:
- Remove unnecessary call to keys() (
remove-dict-keys)
Sourcery Code Quality Report (beta)✅ Merging this PR will increase code quality in the affected files by 0.01 out of 10.
Here are some functions in these files that still need a tune-up:
Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! |
Branch
developrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
developbranch, then run: