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

Ensure that stderr/stdout has flush attr before calling it (Sourcery refactored) #1249

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Sep 13, 2021

Pull Request #1248 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/tqdm/tqdm pull/1248/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!

@sourcery-ai sourcery-ai bot force-pushed the sourcery/pull-1248 branch 2 times, most recently from 2f43363 to 1ea74c3 Compare September 13, 2021 16:00
@codecov
Copy link

codecov bot commented Sep 13, 2021

Codecov Report

Merging #1249 (eac8e7b) into master (140c948) will decrease coverage by 2.44%.
The diff coverage is 76.92%.

❗ Current head eac8e7b differs from pull request most recent head 7b3c166. Consider uploading reports for the commit 7b3c166 to get more accurate results

@@            Coverage Diff             @@
##           master    #1249      +/-   ##
==========================================
- Coverage   89.68%   87.24%   -2.45%     
==========================================
  Files          26       26              
  Lines        1735     1732       -3     
  Branches      287      288       +1     
==========================================
- Hits         1556     1511      -45     
- Misses        133      165      +32     
- Partials       46       56      +10     

@sourcery-ai sourcery-ai bot force-pushed the sourcery/pull-1248 branch 3 times, most recently from 989e110 to b28392f Compare September 13, 2021 16:10
@sourcery-ai sourcery-ai bot force-pushed the sourcery/pull-1248 branch 2 times, most recently from eac8e7b to 7b3c166 Compare October 21, 2021 18:14
postfix = ', ' + postfix if postfix else ''
postfix = f', {postfix}' if postfix else ''
Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm.format_meter refactored with the following changes:

Comment on lines -603 to +608
# find unfixed (`pos >= 0`) overflow (`pos >= nrows - 1`)
instances = list(filter(
lambda i: hasattr(i, "pos") and last <= i.pos,
cls._instances))
# set first found to current `pos`
if instances:
if instances := list(
filter(
lambda i: hasattr(i, "pos") and last <= i.pos,
cls._instances,
)
):
Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm._decr_instances refactored with the following changes:

This removes the following comments ( why? ):

# set first found to current `pos`
# find unfixed (`pos >= 0`) overflow (`pos >= nrows - 1`)

Comment on lines -1023 to +1038
) or dynamic_ncols: # pragma: no cover
): # pragma: no cover
if dynamic_ncols:
dynamic_ncols = _screen_shape_wrapper()
if dynamic_ncols:
ncols, nrows = dynamic_ncols(file)
else:
_dynamic_ncols = _screen_shape_wrapper()
if _dynamic_ncols:
_ncols, _nrows = _dynamic_ncols(file)
if ncols is None:
ncols = _ncols
if nrows is None:
nrows = _nrows

elif _dynamic_ncols := _screen_shape_wrapper():
_ncols, _nrows = _dynamic_ncols(file)
if ncols is None:
ncols = _ncols
if nrows is None:
nrows = _nrows

elif dynamic_ncols: # pragma: no cover
dynamic_ncols = _screen_shape_wrapper()
if dynamic_ncols:
ncols, nrows = dynamic_ncols(file)
Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# pragma: no cover

Comment on lines -1168 to +1170
for obj in iterable:
yield obj
yield from iterable
Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm.__iter__ refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

Comment on lines -1391 to +1392
self.desc = desc + ': ' if desc else ''
self.desc = f'{desc}: ' if desc else ''
Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm.set_description refactored with the following changes:

Comment on lines -1427 to +1431
self.postfix = ', '.join(key + '=' + postfix[key].strip()
for key in postfix.keys())
self.postfix = ', '.join(
f'{key}=' + postfix[key].strip() for key in postfix.keys()
)

Copy link
Author

Choose a reason for hiding this comment

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

Function tqdm.set_postfix refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Feb 14, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.06%.

Quality metrics Before After Change
Complexity 25.85 😞 25.43 😞 -0.42 👍
Method Length 71.76 🙂 72.13 🙂 0.37 👎
Working memory 15.16 😞 15.24 ⛔ 0.08 👎
Quality 47.27% 😞 47.21% 😞 -0.06% 👎
Other metrics Before After Change
Lines 1558 1561 3
Changed files Quality Before Quality After Quality Change
tqdm/std.py 47.27% 😞 47.21% 😞 -0.06% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
tqdm/std.py tqdm.format_meter 73 ⛔ 571.98 ⛔ 29 ⛔ 2.09% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.__init__ 50 ⛔ 565 ⛔ 39 ⛔ 3.63% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.pandas 53 ⛔ 409 ⛔ 13 😞 15.07% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.pandas.inner_generator 26 😞 196 😞 13 😞 31.76% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tqdm/std.py tqdm.update 27 😞 154 😞 14 😞 33.57% 😞 Refactor to reduce nesting. Try splitting into smaller methods. 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.

None yet

1 participant