Skip to content
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

Some refactors we did to make the linter agree with us more (Sourcery refactored) #111

Closed
wants to merge 6 commits into from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Apr 10, 2022

Pull Request #110 refactored by Sourcery.

Since the original Pull Request was opened as a fork in a contributor's
repository, we are unable to create a Pull Request branching from it.

To incorporate these changes, you can either:

  1. Merge this Pull Request instead of the original, or

  2. Ask your contributor to locally incorporate these commits and push them to
    the original Pull Request

    Incorporate changes via command line
    git fetch https://github.com/approvals/ApprovalTests.Python pull/110/head
    git merge --ff-only FETCH_HEAD
    git push

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Help us improve this pull request!

AustinAbro321 and others added 6 commits April 10, 2022 12:56
Co-Authored-By: Austin Abro <AustinAbro321>
Co-Authored-By: Gregor Riegler <gregorriegler>
Co-Authored-By:  <chbndrhnns>
Co-Authored-By: Bernhard Raml <SwamyDev>
    Co-Authored-By: Austin Abro <AustinAbro321>
    Co-Authored-By: Gregor Riegler <gregorriegler>
    Co-Authored-By:  <chbndrhnns>
    Co-Authored-By: Bernhard Raml <SwamyDev>
Co-Authored-By: Austin Abro <AustinAbro321>
Co-Authored-By: Gregor Riegler <gregorriegler>
Co-Authored-By:  <chbndrhnns>
Co-Authored-By: Bernhard Raml <SwamyDev>
…class

Co-Authored-By: Austin Abro <AustinAbro321>
Co-Authored-By: Gregor Riegler <gregorriegler>
Co-Authored-By:  <chbndrhnns>
Co-Authored-By: Bernhard Raml <SwamyDev>
Co-Authored-By: Austin Abro <AustinAbro321>
Co-Authored-By: Gregor Riegler <gregorriegler>
Co-Authored-By:  <chbndrhnns>
Co-Authored-By: Bernhard Raml <SwamyDev>
extension_with_dot = "." + extension_with_dot
extension_with_dot = f".{extension_with_dot}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FileOptions.with_extension refactored with the following changes:

if self.has_scrubber():
return self.fields["scrubber_func"](data)
return data
return self.fields["scrubber_func"](data) if self.has_scrubber() else data
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Options.scrub refactored with the following changes:

Comment on lines 29 to +34
def get_class_name_for_frame(stacktrace: FrameInfo) -> str:
if "self" not in stacktrace[0].f_locals:
name = os.path.splitext(os.path.basename(stacktrace[1]))[0]
else:
name = f"{stacktrace[0].f_locals['self'].__class__.__name__}"
return name
return (
os.path.splitext(os.path.basename(stacktrace[1]))[0]
if "self" not in stacktrace[0].f_locals
else f"{stacktrace[0].f_locals['self'].__class__.__name__}"
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StackFrameNamer.get_class_name_for_frame refactored with the following changes:

Comment on lines 36 to +41
def get_test_frame(self, caller: List[FrameInfo]) -> int:
tmp_array = []
for index, frame in enumerate(caller):
if self.is_test_method(frame):
tmp_array.append(index)
if tmp_array:
if tmp_array := [
index
for index, frame in enumerate(caller)
if self.is_test_method(frame)
]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StackFrameNamer.get_test_frame refactored with the following changes:

Comment on lines 75 to +76
def get_file_name(self) -> str:
class_name = "" if (self.class_name is None) else (self.class_name + ".")
class_name = "" if self.class_name is None else f'{self.class_name}.'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StackFrameNamer.get_file_name refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Apr 10, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 1.18 ⭐ 0.91 ⭐ -0.27 👍
Method Length 17.71 ⭐ 17.60 ⭐ -0.11 👍
Working memory 4.50 ⭐ 4.42 ⭐ -0.08 👍
Quality 91.88% 92.52% 0.64% 👍
Other metrics Before After Change
Lines 181 181 0
Changed files Quality Before Quality After Quality Change
approvaltests/core/namer.py 97.34% ⭐ 97.34% ⭐ 0.00%
approvaltests/core/options.py 95.95% ⭐ 96.17% ⭐ 0.22% 👍
approvaltests/namer/namer_base.py 89.79% ⭐ 89.79% ⭐ 0.00%
approvaltests/namer/stack_frame_namer.py 88.74% ⭐ 90.22% ⭐ 1.48% 👍
approvaltests/reporters/default_reporter_factory.py 95.95% ⭐ 95.63% ⭐ -0.32% 👎
approvaltests/scrubbers/init.py % % %

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

File Function Complexity Length Working Memory Quality Recommendation

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!

@sourcery-ai sourcery-ai bot closed this Apr 17, 2022
@sourcery-ai sourcery-ai bot deleted the sourcery/pull-110 branch April 17, 2022 16:07
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.

None yet

1 participant