-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
collect_ignore.append('docs/conf.py') # uses f-strings | ||
collect_ignore.append('pavement.py') | ||
|
||
|
||
collect_ignore.extend(('docs/conf.py', 'pavement.py')) |
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.
Lines 45-48
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
This removes the following comments ( why? ):
# uses f-strings
state = {} | ||
g = globals() | ||
for k, v in _state_vars.items(): | ||
state[k] = g['_sget_' + v](g[k]) | ||
return state | ||
return {k: g[f'_sget_{v}'](g[k]) for k, v in _state_vars.items()} |
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.
Function __getstate__
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Convert for loop into dictionary comprehension (
dict-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
g['_sset_' + _state_vars[k]](k, g[k], v) | ||
g[f'_sset_{_state_vars[k]}'](k, g[k], v) |
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.
Function __setstate__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
plat = 'macosx-%s-%s' % ('.'.join(_macos_vers()[:2]), m.group(3)) | ||
plat = f"macosx-{'.'.join(_macos_vers()[:2])}-{m.group(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.
Function get_supported_platform
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if not self.requirers: | ||
return 'the application' | ||
return ', '.join(self.requirers) | ||
return 'the application' if not self.requirers else ', '.join(self.requirers) |
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.
Function DistributionNotFound.requirers_str
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
def has_resource(resource_name): | ||
def has_resource(self): |
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.
Function IResourceProvider.has_resource
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
def resource_isdir(resource_name): | ||
def resource_isdir(self): |
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.
Function IResourceProvider.resource_isdir
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
def resource_listdir(resource_name): | ||
def resource_listdir(self): |
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.
Function IResourceProvider.resource_listdir
refactored with the following changes:
- The first argument to instance methods should be
self
(instance-method-first-arg-name
)
if dist is None: | ||
requirers = required_by.get(req, None) | ||
raise DistributionNotFound(req, requirers) | ||
if dist is None: | ||
requirers = required_by.get(req, None) | ||
raise DistributionNotFound(req, requirers) |
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.
Function WorkingSet._resolve_dist
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
)
plugin_projects = list(plugin_env) | ||
# scan project names in alphabetic order | ||
plugin_projects.sort() | ||
|
||
plugin_projects = sorted(plugin_env) |
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.
Function WorkingSet.find_plugins
refactored with the following changes:
- Remove an unnecessary list construction call prior to sorting [×2] (
skip-sorted-list-construction
)
This removes the following comments ( why? ):
# scan project names in alphabetic order
target_path = os.path.join(extract_path, archive_name + '-tmp', *names) | ||
target_path = os.path.join(extract_path, f'{archive_name}-tmp', *names) |
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.
Function ResourceManager.get_cache_path
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
match = _PEP440_FALLBACK.search(version) | ||
if match: | ||
if match := _PEP440_FALLBACK.search(version): |
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.
Function _forgiving_version
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
exc.reason += ' in {} file at path: {}'.format(name, path) | ||
exc.reason += f' in {name} file at path: {path}' |
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.
Function NullProvider.get_metadata
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if self.egg_info: | ||
return self._listdir(self._fn(self.egg_info, name)) | ||
return [] | ||
return self._listdir(self._fn(self.egg_info, name)) if self.egg_info else [] |
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.
Function NullProvider.metadata_listdir
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
script = 'scripts/' + script_name | ||
script = f'scripts/{script_name}' |
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.
Function NullProvider.run_script
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
match = EGG_NAME(basename) | ||
if match: | ||
if match := EGG_NAME(basename): |
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.
Function Distribution.from_location
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
msg = ("Missing 'Version:' header and/or {} file at path: {}").format( | ||
self.PKG_INFO, path | ||
) | ||
msg = f"Missing 'Version:' header and/or {self.PKG_INFO} file at path: {path}" |
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.
Function Distribution.version
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
fails_marker = marker and ( | ||
if fails_marker := marker and ( | ||
invalid_marker(marker) or not evaluate_marker(marker) | ||
) | ||
if fails_marker: | ||
): |
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.
Function Distribution._filter_extras
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
version = _version_from_file(lines) | ||
|
||
return version | ||
return _version_from_file(lines) |
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.
Function Distribution._get_version
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
filename = "%s-%s-py%s" % ( | ||
to_filename(self.project_name), | ||
to_filename(self.version), | ||
self.py_version or PY_MAJOR, | ||
) | ||
filename = f"{to_filename(self.project_name)}-{to_filename(self.version)}-py{self.py_version or PY_MAJOR}" | ||
|
||
if self.platform: | ||
filename += '-' + self.platform | ||
filename += f'-{self.platform}' |
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.
Function Distribution.egg_name
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if self.location: | ||
return "%s (%s)" % (self, self.location) | ||
else: | ||
return str(self) | ||
return f"{self} ({self.location})" if self.location else str(self) |
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.
Function Distribution.__repr__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
return "%s %s" % (self.project_name, version) | ||
return f"{self.project_name} {version}" |
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.
Function Distribution.__str__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
set(super().__dir__()) | ||
| set(attr for attr in self._provider.__dir__() if not attr.startswith('_')) | ||
( | ||
set(super().__dir__()) | ||
| { | ||
attr | ||
for attr in self._provider.__dir__() | ||
if not attr.startswith('_') | ||
} | ||
) |
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.
Function Distribution.__dir__
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
spec = "%s==%s" % (self.project_name, self.parsed_version) | ||
spec = f"{self.project_name}=={self.parsed_version}" | ||
else: | ||
spec = "%s===%s" % (self.project_name, self.parsed_version) | ||
spec = f"{self.project_name}==={self.parsed_version}" |
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.
Function Distribution.as_requirement
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
if group is not None: | ||
return ep_map.get(group, {}) | ||
return ep_map | ||
return ep_map.get(group, {}) if group is not None else ep_map |
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.
Function Distribution.get_entry_map
refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._name}' |
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.
Function _TypeAliasForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._name}' |
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.
Function _TypeAliasForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._name}' |
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.
Function _ConcatenateForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._name}' |
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.
Function _TypeGuardForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return 'typing_extensions.' + self._name | ||
return f'typing_extensions.{self._name}' |
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.
Function _TypeGuardForm.__repr__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Branch
main
refactored 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
main
branch, then run:Help us improve this pull request!