Skip to content

Sourcery Starbot ⭐ refactored Tapuzi/cpython - #1

Open
SourceryAI wants to merge 1 commit into
Tapuzi:masterfrom
SourceryAI:master
Open

Sourcery Starbot ⭐ refactored Tapuzi/cpython#1
SourceryAI wants to merge 1 commit into
Tapuzi:masterfrom
SourceryAI:master

Conversation

@SourceryAI

Copy link
Copy Markdown

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/cpython master
git merge --ff-only FETCH_HEAD
git reset HEAD^

@SourceryAI SourceryAI left a comment

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.

Sourcery timed out performing refactorings.

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

Comment thread setup.py
else:
sysroot = m.group(1)
return sysroot
return '/' if m is None else m.group(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 macosx_sdk_root refactored with the following changes:

Comment thread setup.py
Comment on lines -378 to +376
if ext.name == '_ctypes':
if not self.configure_ctypes(ext):
self.failed.append(ext.name)
return
if ext.name == '_ctypes' and not self.configure_ctypes(ext):
self.failed.append(ext.name)
return

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 find_module_file.PyBuildExt.build_extension refactored with the following changes:

Comment thread setup.py
Comment on lines -946 to +941
if not (min_db_ver <= db_ver <= max_db_ver):
return False
return True
return min_db_ver <= db_ver <= max_db_ver

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 find_module_file.PyBuildExt.detect_modules.allow_db_ver refactored with the following changes:

for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
rc = [node.data for node in nodelist if node.nodeType == node.TEXT_NODE]

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

Comment thread Doc/includes/mp_pool.py
except ZeroDivisionError:
if i == 5:
pass
pass

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

Comment thread Lib/_collections_abc.py
Comment on lines -890 to +881
for v in self:
if v is value or v == value:
return True
return False
return any(v is value or v == value for v in self)

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

  • Use any() instead of for loop (use-any)

Comment thread Lib/_collections_abc.py
Comment on lines -924 to +912
return sum(1 for v in self if v is value or v == value)
return sum(v is value or v == value for v in self)

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

Comment thread Lib/_compat_pickle.py
Comment on lines -165 to +167
REVERSE_IMPORT_MAPPING = dict((v, k) for (k, v) in IMPORT_MAPPING.items())
REVERSE_IMPORT_MAPPING = {v: k for (k, v) in IMPORT_MAPPING.items()}
assert len(REVERSE_IMPORT_MAPPING) == len(IMPORT_MAPPING)
REVERSE_NAME_MAPPING = dict((v, k) for (k, v) in NAME_MAPPING.items())
REVERSE_NAME_MAPPING = {v: k for (k, v) in NAME_MAPPING.items()}

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.

Lines 165-167 refactored with the following changes:

Comment thread Lib/_dummy_thread.py
Comment on lines -113 to +120
if waitflag is None or waitflag:
if not self.locked_status or waitflag is None or waitflag:
self.locked_status = True
return True
else:
if not self.locked_status:
self.locked_status = True
return True
else:
if timeout > 0:
import time
time.sleep(timeout)
return False
if timeout > 0:
import time
time.sleep(timeout)
return False

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

Comment thread Lib/_dummy_thread.py
Comment on lines -161 to +158
else:
global _interrupt
_interrupt = True
global _interrupt
_interrupt = True

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

Comment thread Lib/_markupbase.py
Comment on lines -233 to +238
if j < n:
if rawdata[j] == ">":
return j
self.updatepos(declstartpos, j)
self.error("unexpected char after internal subset")
else:
if j >= n:
return -1
if rawdata[j] == ">":
return j
self.updatepos(declstartpos, j)
self.error("unexpected char after internal subset")

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

Comment thread Lib/_osx_support.py
Comment on lines -44 to +52
if not os.path.isfile(executable):
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
return None
else:
if os.path.isfile(executable):
return executable

for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
# the file exists, we have a shot at spawn working
return f
return 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 _find_executable refactored with the following changes:

Comment thread Lib/_osx_support.py
# User specified different -arch flags in the environ,
# see also distutils.sysconfig
compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
compiler_so += os.environ['ARCHFLAGS'].split()

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

  • Replace assignment with augmented assignment (aug-assign)

Comment thread Lib/_osx_support.py
else:
machine = 'ppc'

machine = 'ppc64' if sys.maxsize >= 2**32 else 'ppc'

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

Comment thread Lib/_pydecimal.py
self._sign = 1
else:
self._sign = 0
self._sign = 1 if m.group('sign') == "-" else 0

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

Comment thread Lib/_pydecimal.py
Comment on lines -3358 to +3319
for dig in self._int:
if dig not in '01':
return False
return True
return all(dig in '01' for dig in self._int)

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

Comment thread Lib/_pydecimal.py
Comment on lines -3390 to +3348
result = "".join([str(int(a)&int(b)) for a,b in zip(opa,opb)])
result = "".join(str(int(a)&int(b)) for a,b in zip(opa,opb))

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

Comment thread Lib/_pydecimal.py
Comment on lines -3414 to +3372
result = "".join([str(int(a)|int(b)) for a,b in zip(opa,opb)])
result = "".join(str(int(a)|int(b)) for a,b in zip(opa,opb))

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

Comment thread Lib/_pydecimal.py
Comment on lines -3431 to +3389
result = "".join([str(int(a)^int(b)) for a,b in zip(opa,opb)])
result = "".join(str(int(a)^int(b)) for a,b in zip(opa,opb))

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

Comment thread Lib/_pyio.py
Comment on lines -233 to -236
elif reading:
buffer = BufferedReader(raw, buffering)
else:
raise ValueError("unknown mode: %r" % mode)

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

Comment thread Lib/_pyio.py
Comment on lines -696 to +694
if read1:
data = self.read1(len(b))
else:
data = self.read(len(b))
data = self.read1(len(b)) if read1 else self.read(len(b))

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

Comment thread Lib/_pyio.py
Comment on lines -1512 to +1507
os.set_inheritable(fd, False)

os.set_inheritable(owned_fd, False)

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

Comment thread Lib/_pyio.py
Comment on lines -1947 to +1948
if encoding is None:
try:
import locale
except ImportError:
# Importing locale may fail if Python is being built
encoding = "ascii"
else:
encoding = locale.getpreferredencoding(False)
if encoding is None:
try:
import locale
except ImportError:
# Importing locale may fail if Python is being built
encoding = "ascii"
else:
encoding = locale.getpreferredencoding(False)

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

Comment thread Lib/_pyio.py
Comment on lines -2073 to +2067
if encoding is None:
errors = self._errors
else:
errors = 'strict'
errors = self._errors if encoding is None else 'strict'

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

Comment thread Lib/_pyio.py
Comment on lines -2309 to +2300
skip_back = skip_back * 2
skip_back *= 2

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

  • Replace assignment with augmented assignment (aug-assign)

Comment thread Lib/argparse.py
Comment on lines -268 to +266
invocation_length = max([len(s) for s in invocations])
invocation_length = max(len(s) for s in invocations)

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

Comment thread Lib/argparse.py
Comment on lines -291 to +290
return ''.join([part
for part in part_strings
if part and part is not SUPPRESS])
return ''.join(part for part in part_strings
if part and part is not SUPPRESS)

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

Comment thread Lib/argparse.py
Comment on lines -346 to +343
if prefix is not None:
line_len = len(prefix) - 1
else:
line_len = len(indent) - 1
line_len = len(prefix) - 1 if prefix is not None else len(indent) - 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 HelpFormatter._format_usage.get_lines refactored with the following changes:

Comment thread Lib/argparse.py
Comment on lines -585 to +594
result = '%s' % get_metavar(1)
return '%s' % get_metavar(1)
elif action.nargs == OPTIONAL:
result = '[%s]' % get_metavar(1)
return '[%s]' % get_metavar(1)
elif action.nargs == ZERO_OR_MORE:
result = '[%s [%s ...]]' % get_metavar(2)
return '[%s [%s ...]]' % get_metavar(2)
elif action.nargs == ONE_OR_MORE:
result = '%s [%s ...]' % get_metavar(2)
return '%s [%s ...]' % get_metavar(2)
elif action.nargs == REMAINDER:
result = '...'
return '...'
elif action.nargs == PARSER:
result = '%s ...' % get_metavar(1)
return '%s ...' % get_metavar(1)
elif action.nargs == SUPPRESS:
result = ''
return ''
else:
formats = ['%s' for _ in range(action.nargs)]
result = ' '.join(formats) % get_metavar(action.nargs)
return result
return ' '.join(formats) % get_metavar(action.nargs)

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

Comment thread Lib/argparse.py
Comment on lines -612 to +605
choices_str = ', '.join([str(c) for c in params['choices']])
choices_str = ', '.join(str(c) for c in params['choices'])

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

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.

1 participant