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

Sourcery refactored CPython37 branch #1

Open
wants to merge 1 commit into
base: CPython37
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Feb 16, 2022

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

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from kayhayen February 16, 2022 10:18
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

active = search_mode.consider(dirname, filename)

if active:
if active := search_mode.consider(dirname, filename):
Copy link
Author

Choose a reason for hiding this comment

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

Function checkDir refactored with the following changes:

Comment on lines -89 to +99
if line.find("set(attr for attr in dir(g) if not attr.startswith('__')) >= expected") != -1:
return True
elif line.find("isinstance(g, types.GeneratorType)") != -1:
return True
else:
return False
return (
line.find(
"set(attr for attr in dir(g) if not attr.startswith('__')) >= expected"
)
!= -1
or line.find(
"set(attr for attr in dir(g) if not attr.startswith('__')) >= expected"
)
== -1
and line.find("isinstance(g, types.GeneratorType)") != -1
)
Copy link
Author

Choose a reason for hiding this comment

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

Function filter_genexps refactored with the following changes:

if x < 0: x = 0
x = max(x, 0)
Copy link
Author

Choose a reason for hiding this comment

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

Function C.setx refactored with the following changes:

if x < 0: x = 0
x = max(x, 0)
Copy link
Author

Choose a reason for hiding this comment

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

Function C.setx refactored with the following changes:

return [next(g) for i in range(n)]
return [next(g) for _ in range(n)]
Copy link
Author

Choose a reason for hiding this comment

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

Function firstn refactored with the following changes:

Comment on lines -863 to +853
for x in self.parent.generator:
yield x
yield from self.parent.generator
Copy link
Author

Choose a reason for hiding this comment

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

Function disjointSet.generate refactored with the following changes:

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

Comment on lines -925 to +918
try:
1//0
except ZeroDivisionError:
yield 666
except:
pass
1//0
except ZeroDivisionError:
yield 666
except:
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

Comment on lines -979 to +967
if 0:
yield
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

Comment on lines -996 to +983
if 0:
yield 1
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

Comment on lines -1013 to +999
if "":
yield None
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

Comment on lines -1031 to -1049
try:
if x==4:
pass
elif 0:
try:
1//0
except SyntaxError:
pass
else:
if 0:
while 12:
x += 1
yield 2 # don't blink
f(a, b, c, d, e)
else:
pass
except:
x = 1
return
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

This removes the following comments ( why? ):

# don't blink

Comment on lines -1104 to +1070
if 0:
return
if 0:
yield 2
pass
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

@@ -1315,7 +1278,6 @@ def f():
def f():
yield 1
return
yield 2 # never reached
Copy link
Author

Choose a reason for hiding this comment

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

Function f refactored with the following changes:

This removes the following comments ( why? ):

# never reached

Comment on lines -1415 to +1377
for i in range(n):
yield i
yield from range(n)
Copy link
Author

Choose a reason for hiding this comment

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

Function yrange refactored with the following changes:

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

Comment on lines -1454 to +1415
for i in yrange(n):
yield i
yield from yrange(n)
Copy link
Author

Choose a reason for hiding this comment

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

Function zrange refactored with the following changes:

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

Comment on lines -95 to +94
for x in {i for i in range(n)}:
yield x
yield from set(range(n))
Copy link
Author

Choose a reason for hiding this comment

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

Function grange refactored with the following changes:

Comment on lines -245 to +243
items = {(lambda: y) for i in range(5)}
items = {lambda: y for _ in range(5)}
Copy link
Author

Choose a reason for hiding this comment

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

Function test_func refactored with the following changes:

CHECK_TIMINGS = False # making true makes tests take a lot longer
# and can sometimes cause some non-serious
# failures because some calls block a bit
# longer than expected
if CHECK_TIMINGS:
if CHECK_TIMINGS := False:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 94-98 refactored with the following changes:

This removes the following comments ( why? ):

# longer than expected
# failures because some calls block a bit
# making true makes tests take a lot longer
# and can sometimes cause some non-serious

Comment on lines -359 to +356
exitcode = self._kill_process(multiprocessing.Process.terminate)
if os.name != 'nt':
exitcode = self._kill_process(multiprocessing.Process.terminate)
Copy link
Author

Choose a reason for hiding this comment

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

Function _TestProcess.test_terminate refactored with the following changes:

Comment on lines -364 to +361
exitcode = self._kill_process(multiprocessing.Process.kill)
if os.name != 'nt':
exitcode = self._kill_process(multiprocessing.Process.kill)
Copy link
Author

Choose a reason for hiding this comment

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

Function _TestProcess.test_kill refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Feb 16, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 3.09 ⭐ 3.04 ⭐ -0.05 👍
Method Length 57.47 ⭐ 57.34 ⭐ -0.13 👍
Working memory 6.06 ⭐ 6.04 ⭐ -0.02 👍
Quality 75.15% 75.21% 0.06% 👍
Other metrics Before After Change
Lines 68687 68429 -258
Changed files Quality Before Quality After Quality Change
run_all.py 36.32% 😞 35.57% 😞 -0.75% 👎
update_doctest_generated.py 83.73% ⭐ 83.31% ⭐ -0.42% 👎
doctest_generated/test_descrtut.py 98.26% ⭐ 98.43% ⭐ 0.17% 👍
doctest_generated/test_generators.py 93.34% ⭐ 94.69% ⭐ 1.35% 👍
doctest_generated/test_genexps.py 62.95% 🙂 60.46% 🙂 -2.49% 👎
doctest_generated/test_itertools.py 73.36% 🙂 73.58% 🙂 0.22% 👍
doctest_generated/test_listcomps.py 83.45% ⭐ 83.66% ⭐ 0.21% 👍
doctest_generated/test_setcomps.py 75.23% ⭐ 75.23% ⭐ 0.00%
test/_test_multiprocessing.py 75.45% ⭐ 75.67% ⭐ 0.22% 👍
test/bytecode_helper.py 76.33% ⭐ 77.54% ⭐ 1.21% 👍
test/curses_tests.py 70.75% 🙂 72.32% 🙂 1.57% 👍
test/datetimetester.py 71.07% 🙂 71.12% 🙂 0.05% 👍
test/fork_wait.py 74.83% 🙂 78.21% ⭐ 3.38% 👍
test/list_tests.py 76.16% ⭐ 76.18% ⭐ 0.02% 👍
test/lock_tests.py 82.26% ⭐ 82.30% ⭐ 0.04% 👍
test/make_ssl_certs.py 61.07% 🙂 61.07% 🙂 0.00%
test/mapping_tests.py 77.34% ⭐ 77.38% ⭐ 0.04% 👍
test/mock_socket.py 95.99% ⭐ 96.10% ⭐ 0.11% 👍
test/multibytecodec_support.py 75.35% ⭐ 76.03% ⭐ 0.68% 👍
test/pickletester.py 78.93% ⭐ 79.10% ⭐ 0.17% 👍
test/profilee.py 96.34% ⭐ 96.40% ⭐ 0.06% 👍
test/pydocfodder.py 99.44% ⭐ 99.44% ⭐ 0.00%
test/pythoninfo.py 78.14% ⭐ 78.06% ⭐ -0.08% 👎
test/re_tests.py 58.82% 🙂 56.35% 🙂 -2.47% 👎
test/reperf.py 85.96% ⭐ 85.96% ⭐ 0.00%
test/seq_tests.py 79.71% ⭐ 79.61% ⭐ -0.10% 👎
test/sortperf.py 61.12% 🙂 62.96% 🙂 1.84% 👍
test/string_tests.py 70.22% 🙂 70.51% 🙂 0.29% 👍
test/test__locale.py 70.19% 🙂 70.22% 🙂 0.03% 👍
test/test__osx_support.py 82.40% ⭐ 82.40% ⭐ 0.00%
test/test_aifc.py 72.72% 🙂 72.72% 🙂 0.00%
test/test_array.py 77.07% ⭐ 77.12% ⭐ 0.05% 👍
test/test_ast.py 80.47% ⭐ 80.45% ⭐ -0.02% 👎
test/test_asyncgen.py 84.92% ⭐ 84.91% ⭐ -0.01% 👎
test/test_asynchat.py 83.17% ⭐ 83.22% ⭐ 0.05% 👍
test/test_atexit.py 93.03% ⭐ 93.10% ⭐ 0.07% 👍
test/test_augassign.py 79.72% ⭐ 79.59% ⭐ -0.13% 👎
test/test_baseexception.py 63.43% 🙂 63.43% 🙂 0.00%
test/test_bigmem.py 80.21% ⭐ 80.21% ⭐ 0.00%
test/test_binhex.py 93.79% ⭐ 94.50% ⭐ 0.71% 👍
test/test_binop.py 87.24% ⭐ 87.11% ⭐ -0.13% 👎
test/test_bisect.py 80.34% ⭐ 80.53% ⭐ 0.19% 👍
test/test_bool.py 80.36% ⭐ 80.31% ⭐ -0.05% 👎
test/test_buffer.py 48.25% 😞 48.22% 😞 -0.03% 👎
test/test_builtin.py 76.52% ⭐ 76.38% ⭐ -0.14% 👎
test/test_bytes.py 79.62% ⭐ 79.65% ⭐ 0.03% 👍
test/test_calendar.py 89.34% ⭐ 89.37% ⭐ 0.03% 👍
test/test_capi.py 81.86% ⭐ 82.69% ⭐ 0.83% 👍
test/test_cgi.py 80.07% ⭐ 80.17% ⭐ 0.10% 👍
test/test_class.py 77.09% ⭐ 77.09% ⭐ 0.00%
test/test_cmath.py 66.14% 🙂 66.25% 🙂 0.11% 👍
test/test_code.py 88.62% ⭐ 88.62% ⭐ 0.00%
test/test_codeccallbacks.py 77.85% ⭐ 78.06% ⭐ 0.21% 👍
test/test_codecs.py 76.40% ⭐ 76.69% ⭐ 0.29% 👍
test/test_collections.py 71.96% 🙂 72.12% 🙂 0.16% 👍
test/test_compare.py 89.74% ⭐ 89.74% ⭐ 0.00%
test/test_compile.py 83.23% ⭐ 82.95% ⭐ -0.28% 👎
test/test_complex.py 69.14% 🙂 69.24% 🙂 0.10% 👍
test/test_concurrent_futures.py 87.70% ⭐ 87.76% ⭐ 0.06% 👍
test/test_configparser.py 72.92% 🙂 73.19% 🙂 0.27% 👍
test/test_context.py 71.94% 🙂 71.91% 🙂 -0.03% 👎
test/test_contextlib.py 87.40% ⭐ 87.43% ⭐ 0.03% 👍
test/test_contextlib_async.py 86.81% ⭐ 86.88% ⭐ 0.07% 👍
test/test_copy.py 87.43% ⭐ 87.43% ⭐ 0.00%
test/test_coroutines.py 87.13% ⭐ 87.14% ⭐ 0.01% 👍
test/test_csv.py 83.50% ⭐ 83.56% ⭐ 0.06% 👍
test/test_dataclasses.py 79.95% ⭐ 79.94% ⭐ -0.01% 👎
test/test_dbm_dumb.py 83.10% ⭐ 83.04% ⭐ -0.06% 👎
test/test_decimal.py 62.02% 🙂 62.08% 🙂 0.06% 👍
test/test_decorators.py 87.75% ⭐ 87.75% ⭐ 0.00%
test/test_deque.py 73.82% 🙂 74.09% 🙂 0.27% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
test/test_buffer.py TestBufferProtocol.verify 95 ⛔ 1112 ⛔ 28 ⛔ 1.42% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/test_buffer.py TestBufferProtocol.test_py_buffer_to_contiguous 68 ⛔ 790 ⛔ 15 😞 9.66% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/test_buffer.py TestBufferProtocol.test_ndarray_getbuf 62 ⛔ 531 ⛔ 15 😞 10.46% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/test_decimal.py IBMTestCases.eval_equation 61 ⛔ 557 ⛔ 14 😞 11.74% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/test_decimal.py SignatureTest.test_inspect_types 37 ⛔ 442 ⛔ 16 ⛔ 14.81% ⛔ 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.

0 participants