-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
Conversation
| if isinstance(data, list): | ||
| self._str = data | ||
| else: | ||
| self._str = data.split('\n') # store string as list of lines | ||
|
|
||
| self._str = data if isinstance(data, list) else data.split('\n') |
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 Reader.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# store string as list of lines
| if not self.eof(): | ||
| out = self[self._l] | ||
| self._l += 1 | ||
| return out | ||
| else: | ||
| if self.eof(): | ||
| return '' | ||
| out = self[self._l] | ||
| self._l += 1 | ||
| return out |
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 Reader.read refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if self._l + n < len(self._str): | ||
| return self[self._l + n] | ||
| else: | ||
| return '' | ||
| return self[self._l + n] if self._l + n < len(self._str) 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 Reader.peek refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if single_element_is_type: | ||
| arg_name, arg_type = '', header | ||
| else: | ||
| arg_name, arg_type = header, '' | ||
|
|
||
| arg_name, arg_type = ('', header) if single_element_is_type else (header, '') |
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 NumpyDocString._parse_param_list refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| section_names = set([section for section, content in sections]) | ||
| section_names = {section for section, content in sections} |
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 NumpyDocString._parse refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace unneeded comprehension with generator (
comprehension-to-generator)
| for line in self['References']: | ||
| m = re.match(r'.. \[([a-z0-9._-]+)\]', line, re.I) | ||
| if m: | ||
| items.append(m.group(1)) | ||
| items.extend( | ||
| m.group(1) | ||
| for line in self['References'] | ||
| if (m := re.match(r'.. \[([a-z0-9._-]+)\]', line, re.I)) | ||
| ) | ||
|
|
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 SphinxDocString._str_references refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend) - Use named expression to simplify assignment and conditional (
use-named-expression)
| if (self.use_plots and re.search(IMPORT_MATPLOTLIB_RE, examples_str) | ||
| and 'plot::' not in examples_str): | ||
| out = [] | ||
| out += self._str_header('Examples') | ||
| out += ['.. plot::', ''] | ||
| out += self._str_indent(self['Examples']) | ||
| out += [''] | ||
| return out | ||
| else: | ||
| if ( | ||
| not self.use_plots | ||
| or not re.search(IMPORT_MATPLOTLIB_RE, examples_str) | ||
| or 'plot::' in examples_str | ||
| ): | ||
| return self._str_section('Examples') | ||
| out = [] | ||
| out += self._str_header('Examples') | ||
| out += ['.. plot::', ''] | ||
| out += self._str_indent(self['Examples']) | ||
| out += [''] | ||
| return out |
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 SphinxDocString._str_examples refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| ns = dict((k, '\n'.join(v)) for k, v in ns.items()) | ||
| ns = {k: '\n'.join(v) for k, v in ns.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 SphinxDocString.__str__ refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension)
| m = re.match(r'^\.\. +\[(%s)\]' % | ||
| app.config.numpydoc_citation_re, | ||
| line, re.I) | ||
| if m: | ||
| if m := re.match( | ||
| r'^\.\. +\[(%s)\]' % app.config.numpydoc_citation_re, line, re.I | ||
| ): | ||
| references.add(m.group(1)) | ||
|
|
||
| if references: | ||
| # we use a hash to mangle the reference name to avoid invalid names | ||
| sha = hashlib.sha256() | ||
| sha.update(name.encode('utf8')) | ||
| prefix = 'R' + sha.hexdigest()[:HASH_LEN] | ||
| prefix = f'R{sha.hexdigest()[:HASH_LEN]}' | ||
|
|
||
| for r in references: | ||
| new_r = prefix + '-' + r | ||
| new_r = f'{prefix}-{r}' |
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 rename_references refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| sig = (doc['Signature'] | ||
| or _clean_text_signature(getattr(obj, '__text_signature__', None))) | ||
| if sig: | ||
| if sig := ( | ||
| doc['Signature'] | ||
| or _clean_text_signature(getattr(obj, '__text_signature__', None)) | ||
| ): |
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 mangle_signature refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| metadata = {'version': __version__, | ||
| return {'version': __version__, | ||
| 'parallel_read_safe': True} | ||
| return metadata |
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 setup refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| # Ensure that the validation check set contains only valid error codes | ||
| invalid_error_codes = config.numpydoc_validation_checks - valid_error_codes | ||
| if invalid_error_codes: | ||
| if ( | ||
| invalid_error_codes := config.numpydoc_validation_checks | ||
| - valid_error_codes | ||
| ): |
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 update_config refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Simplify generator expression (
simplify-generator)
This removes the following comments ( why? ):
# Ensure that the validation check set contains only valid error codes
| for i, line in enumerate(lines): | ||
| for line in 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 match_items refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| for maxsplit in range(0, name.count(".") + 1): | ||
| for maxsplit in range(name.count(".") + 1): |
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 Validator._load_obj refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
| and not (not signature_params and not all_params) | ||
| and (signature_params or all_params) |
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 Validator.parameter_mismatches refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| results = [] | ||
| tokens = pattern.split(s) | ||
| n = len(tokens) | ||
| if n > 1: | ||
| results = [] |
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 make_xref._split_and_apply_re refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
| for ii, (aa, bb) in enumerate(zip(a, b)): | ||
| for aa, bb in zip(a, b): |
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 line_by_line_compare refactored with the following changes:
- Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
| if func == 'func_h': | ||
| if ( | ||
| func == 'func_h' | ||
| or func not in ['baz.obj_q', '~baz.obj_r'] | ||
| and func != 'class_j' | ||
| and func in ['func_h1', 'func_h2'] | ||
| ): | ||
| assert role == 'meth' | ||
| elif func == 'baz.obj_q' or func == '~baz.obj_r': | ||
| elif func in ['baz.obj_q', '~baz.obj_r']: | ||
| assert role == 'obj' | ||
| elif func == 'class_j': | ||
| assert role == 'class' | ||
| elif func in ['func_h1', 'func_h2']: | ||
| assert role == 'meth' |
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 test_see_also refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks) - Remove redundant conditional (
remove-redundant-if) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if obj is None: | ||
| # Only instances have actual _data, not classes | ||
| return self | ||
| else: | ||
| return obj._data.axes[self.axis] | ||
| return self if obj is None else obj._data.axes[self.axis] |
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 test_nonstandard_property.SpecialProperty.__get__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# Only instances have actual _data, not classes
| cfg = dict() | ||
| cfg = {} |
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 test_args_and_kwargs refactored with the following changes:
- Replace dict() with {} (
dict-literal)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.21%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. 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! Help us improve this quality report! |
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!