Skip to content

Sourcery refactored master branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Oct 10, 2022

Copy link
Copy Markdown

Branch master 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 master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
sourcery-ai Bot requested a review from youandvern October 10, 2022 19:02

def printExpr(e1,e2=''):
print('$$' + str(e1) + r'\ \ \ \ \ \ \ \ \ ' + str(e2) + '$$\n')
print(f'$${str(e1)}' + r'\ \ \ \ \ \ \ \ \ ' + str(e2) + '$$\n')

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 printExpr refactored with the following changes:

Comment thread latexexpr/__init__.py
Comment on lines -215 to +219
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

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.strResult refactored with the following changes:

Comment thread latexexpr/__init__.py
Comment on lines -296 to +295
return '%s' % (self.name)
return '%s = %s' % (self.name, self.strResultWithUnit())
return f'{self.name}'
return f'{self.name} = {self.strResultWithUnit()}'

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.__str__ refactored with the following changes:

Comment thread latexexpr/__init__.py
Comment on lines -320 to +331
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
)

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.toLaTeXVariable refactored with the following changes:

Comment thread latexexpr/__init__.py
Comment on lines -455 to +467
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)}'
)

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 Operation.__init__ refactored with the following changes:

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)}")

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 _operation2sympy refactored with the following changes:

Comment thread latexexpr/sympy/__init__.py Outdated
Comment on lines -175 to -179
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])

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 _sympy2operation refactored with the following changes:

Comment on lines -276 to +271
raise TypeError("Unsupported type (%s) for simplify" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for simplify")

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 simplify refactored with the following changes:

Comment on lines -319 to +313
raise TypeError("Unsupported type (%s) for expand" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for expand")

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 expand refactored with the following changes:

Comment on lines -361 to +354
raise TypeError("Unsupported type (%s) for factor" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for factor")

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 factor refactored with the following changes:

Comment on lines -405 to +397
raise TypeError("Unsupported type (%s) for collect" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for collect")

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 collect refactored with the following changes:

Comment on lines -450 to +441
raise TypeError("Unsupported type (%s) for cancel" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for cancel")

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 cancel refactored with the following changes:

Comment on lines -487 to +477
raise TypeError("Unsupported type (%s) for apart" %
(arg.__class__.__name__))
raise TypeError(f"Unsupported type ({arg.__class__.__name__}) for apart")

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 apart refactored with the following changes:

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2022

Copy link
Copy Markdown
Author

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.27%.

Quality metrics Before After Change
Complexity 17.12 🙂 16.53 🙂 -0.59 👍
Method Length 66.59 🙂 65.98 🙂 -0.61 👍
Working memory 9.48 🙂 9.34 🙂 -0.14 👍
Quality 55.50% 🙂 55.77% 🙂 0.27% 👍
Other metrics Before After Change
Lines 1904 1903 -1
Changed files Quality Before Quality After Quality Change
examples/example4/example4.py 60.58% 🙂 60.57% 🙂 -0.01% 👎
latexexpr/init.py 60.99% 🙂 60.87% 🙂 -0.12% 👎
latexexpr/sympy/init.py 39.96% 😞 41.26% 😞 1.30% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
latexexpr/sympy/init.py _operation2sympy 44 ⛔ 651 ⛔ 23 ⛔ 7.16% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
latexexpr/sympy/init.py _sympy2operation 62 ⛔ 520 ⛔ 13 😞 13.18% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
latexexpr/init.py Operation.result 67 ⛔ 374 ⛔ 8 🙂 23.55% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
latexexpr/init.py Operation.__str 67 ⛔ 370 ⛔ 8 🙂 23.62% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
latexexpr/init.py Expression.toLaTeXVariable 23 😞 99 🙂 17 ⛔ 39.22% 😞 Refactor to reduce nesting. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants