Sourcery refactored master branch - #1
Conversation
|
|
||
| def printExpr(e1,e2=''): | ||
| print('$$' + str(e1) + r'\ \ \ \ \ \ \ \ \ ' + str(e2) + '$$\n') | ||
| print(f'$${str(e1)}' + r'\ \ \ \ \ \ \ \ \ ' + str(e2) + '$$\n') |
There was a problem hiding this comment.
Function printExpr refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| f = format if format else self.format | ||
| f = format or self.format | ||
| e = exponent if exponent != 0 else self.exponent | ||
| result = self.value | ||
| if e == 0: | ||
| if result < 0.: | ||
| return r'\left( %s \right)' % f % result | ||
| return '%s' % f % result | ||
| return r'\left( %s \right)' % f % result if result < 0. else f'{f}' % result |
There was a problem hiding this comment.
Function Variable.strResult refactored with the following changes:
- Simplify if expression by using or (
or-if-exp-identity) - Swap positions of nested conditionals (
swap-nested-ifs) - Lift code into else after jump in control flow (
reintroduce-else) - Hoist nested repeated code outside conditional statements (
hoist-similar-statement-from-if) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace if statement with if expression (
assign-if-exp)
| return '%s' % (self.name) | ||
| return '%s = %s' % (self.name, self.strResultWithUnit()) | ||
| return f'{self.name}' | ||
| return f'{self.name} = {self.strResultWithUnit()}' |
There was a problem hiding this comment.
Function Variable.__str__ refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring)
| if not what in whats: | ||
| raise LaTeXExpressionError('%s not in %s' % (what, whats)) | ||
| val = self.value if what == 'float' else self.strResult() if what == 'str' else self.strResultWithUnit( | ||
| ) if what == 'valunit' else str(self) if what == 'all' or what == 'subst' else None | ||
| if what not in whats: | ||
| raise LaTeXExpressionError(f'{what} not in {whats}') | ||
| val = ( | ||
| self.value | ||
| if what == 'float' | ||
| else self.strResult() | ||
| if what == 'str' | ||
| else self.strResultWithUnit() | ||
| if what == 'valunit' | ||
| else str(self) | ||
| if what in ['all', 'subst'] | ||
| else None | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function Variable.toLaTeXVariable refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| if not type in _supportedOperations: | ||
| raise LaTeXExpressionError('operation %s not in supported operations %s' % ( | ||
| type, str(_supportedOperations))) | ||
| if type not in _supportedOperations: | ||
| raise LaTeXExpressionError( | ||
| f'operation {type} not in supported operations {str(_supportedOperations)}' | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function Operation.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| return _operation2sympy(arg.operation, varMap, sf) | ||
| if not isinstance(arg, latexexpr.Operation): | ||
| raise TypeError("TODO " + str(type(arg)) + str(arg)) | ||
| raise TypeError(f"TODO {str(type(arg))}{str(arg)}") |
There was a problem hiding this comment.
Function _operation2sympy refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| elif len(args) == 2 and isinstance(args[1], latexexpr.Operation) and args[1].type == latexexpr._DIV: | ||
| if args[1].args[0].value == 1.: | ||
| return args[0] / args[1].args[1] | ||
| if all(a.type == latexexpr._LN for a in (args[0], args[1].args[0])): | ||
| return latexexpr._LOG(args[0], args[0].args[1]) |
There was a problem hiding this comment.
Function _sympy2operation refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| raise TypeError("Unsupported type (%s) for simplify" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for simplify") |
There was a problem hiding this comment.
Function simplify refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise TypeError("Unsupported type (%s) for expand" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for expand") |
There was a problem hiding this comment.
Function expand refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise TypeError("Unsupported type (%s) for factor" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for factor") |
There was a problem hiding this comment.
Function factor refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise TypeError("Unsupported type (%s) for collect" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for collect") |
There was a problem hiding this comment.
Function collect refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise TypeError("Unsupported type (%s) for cancel" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for cancel") |
There was a problem hiding this comment.
Function cancel refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| raise TypeError("Unsupported type (%s) for apart" % | ||
| (arg.__class__.__name__)) | ||
| raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for apart") |
There was a problem hiding this comment.
Function apart refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.27%.
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
masterrefactored 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
masterbranch, then run:Help us improve this pull request!