Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Doc/includes/minidom-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
dom = xml.dom.minidom.parseString(document)

def getText(nodelist):
rc = []
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:

return ''.join(rc)

def handleSlideshow(slideshow):
Expand Down
3 changes: 1 addition & 2 deletions Doc/includes/mp_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def test():
try:
x = next(it)
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:

except StopIteration:
break
else:
Expand Down
8 changes: 4 additions & 4 deletions Doc/includes/mp_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ def test():
task_queue.put(task)

# Start worker processes
for i in range(NUMBER_OF_PROCESSES):
for _ in range(NUMBER_OF_PROCESSES):
Process(target=worker, args=(task_queue, done_queue)).start()

# Get and print results
print('Unordered results:')
for i in range(len(TASKS1)):
for item in TASKS1:
Comment on lines -54 to +59

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:

print('\t', done_queue.get())

# Add more tasks using `put()`
for task in TASKS2:
task_queue.put(task)

# Get and print some more results
for i in range(len(TASKS2)):
for _ in TASKS2:
print('\t', done_queue.get())

# Tell child processes to stop
for i in range(NUMBER_OF_PROCESSES):
for _ in range(NUMBER_OF_PROCESSES):
task_queue.put('STOP')


Expand Down
5 changes: 1 addition & 4 deletions Doc/includes/sqlite3/row_factory.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import sqlite3

def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
return {col[0]: row[idx] for idx, col in enumerate(cursor.description)}

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


con = sqlite3.connect(":memory:")
con.row_factory = dict_factory
Expand Down
7 changes: 2 additions & 5 deletions Doc/includes/tzinfo_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import time as _time

STDOFFSET = timedelta(seconds = -_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds = -_time.altzone)
else:
DSTOFFSET = STDOFFSET
DSTOFFSET = timedelta(seconds=-_time.altzone) if _time.daylight else STDOFFSET

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


DSTDIFF = DSTOFFSET - STDOFFSET

Expand Down Expand Up @@ -93,7 +90,7 @@ def first_sunday_on_or_after(dt):
def us_dst_range(year):
# Find start and end times for US DST. For years before 1967, return
# start = end for no DST.
if 2006 < year:
if year > 2006:
Comment on lines -96 to +93

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

dststart, dstend = DSTSTART_2007, DSTEND_2007
elif 1986 < year < 2007:
dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006
Expand Down
4 changes: 1 addition & 3 deletions Doc/tools/extensions/c_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def add_annotations(self, app, doctree):
if name.startswith("c."):
name = name[2:]
entry = self.get(name)
if not entry:
continue
elif entry.result_type not in ("PyObject*", "PyVarObject*"):
if not entry or entry.result_type not in ("PyObject*", "PyVarObject*"):

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

continue
if entry.result_refs is None:
rc = 'Return value: Always NULL.'
Expand Down
14 changes: 4 additions & 10 deletions Doc/tools/extensions/suspicious.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ def write_log_entry(self, lineno, issue, text):
f = open(self.log_file_name, 'a')
writer = csv.writer(f, dialect)
writer.writerow([self.docname, lineno, issue, text.strip()])
f.close()

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

else:
f = open(self.log_file_name, 'ab')
writer = csv.writer(f, dialect)
writer.writerow([self.docname.encode('utf-8'),
lineno,
issue.encode('utf-8'),
text.strip().encode('utf-8')])
f.close()

f.close()

def load_rules(self, filename):
"""Load database of previously ignored issues.
Expand All @@ -184,21 +184,15 @@ def load_rules(self, filename):
self.info("loading ignore rules... ", nonl=1)
self.rules = rules = []
try:
if py3:
f = open(filename, 'r')
else:
f = open(filename, 'rb')
f = open(filename, 'r') if py3 else open(filename, 'rb')

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

except IOError:
return
for i, row in enumerate(csv.reader(f)):
if len(row) != 4:
raise ValueError(
"wrong format in %s, line %d: %s" % (filename, i+1, row))
docname, lineno, issue, text = row
if lineno:
lineno = int(lineno)
else:
lineno = None
lineno = int(lineno) if lineno else None
if not py3:
docname = docname.decode('utf-8')
issue = issue.decode('utf-8')
Expand Down
22 changes: 5 additions & 17 deletions Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,7 @@ def __le__(self, other):
return NotImplemented
if len(self) > len(other):
return False
for elem in self:
if elem not in other:
return False
return True
return all(elem in other for elem 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 Set.__le__ refactored with the following changes:


def __lt__(self, other):
if not isinstance(other, Set):
Expand All @@ -452,10 +449,7 @@ def __ge__(self, other):
return NotImplemented
if len(self) < len(other):
return False
for elem in other:
if elem not in self:
return False
return True
return all(elem in self for elem in other)
Comment on lines -455 to +452

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


def __eq__(self, other):
if not isinstance(other, Set):
Expand All @@ -480,10 +474,7 @@ def __and__(self, other):

def isdisjoint(self, other):
'Return True if two sets have a null intersection.'
for value in other:
if value in self:
return False
return True
return all(value not in self for value in other)
Comment on lines -483 to +477

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


def __or__(self, other):
if not isinstance(other, Iterable):
Expand Down Expand Up @@ -887,10 +878,7 @@ def __iter__(self):
return

def __contains__(self, value):
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)
Comment on lines -890 to +881

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)


def __reversed__(self):
for i in reversed(range(len(self))):
Expand Down Expand Up @@ -921,7 +909,7 @@ def index(self, value, start=0, stop=None):

def count(self, value):
'S.count(value) -> integer -- return number of occurrences of value'
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)
Comment on lines -924 to +912

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:


Sequence.register(tuple)
Sequence.register(str)
Expand Down
4 changes: 2 additions & 2 deletions Lib/_compat_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
NAME_MAPPING[("multiprocessing", excname)] = ("multiprocessing.context", excname)

# Same, but for 3.x to 2.x
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()}
Comment on lines -165 to +167

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:

assert len(REVERSE_NAME_MAPPING) == len(NAME_MAPPING)

# Non-mutual mappings.
Expand Down
19 changes: 7 additions & 12 deletions Lib/_dummy_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,14 @@ def acquire(self, waitflag=None, timeout=-1):
aren't triggered and throw a little fit.

"""
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
Comment on lines -113 to +120

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:


__enter__ = acquire

Expand Down Expand Up @@ -158,6 +154,5 @@ def interrupt_main():
KeyboardInterrupt upon exiting."""
if _main:
raise KeyboardInterrupt
else:
global _interrupt
_interrupt = True
global _interrupt
_interrupt = True
Comment on lines -161 to +158

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:

11 changes: 5 additions & 6 deletions Lib/_markupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ def _parse_doctype_subset(self, i, declstartpos):
j = j + 1
while j < n and rawdata[j].isspace():
j = j + 1
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")
Comment on lines -233 to +238

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:

elif c.isspace():
j = j + 1
else:
Expand Down
24 changes: 10 additions & 14 deletions Lib/_osx_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ def _find_executable(executable, path=None):
if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'

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
Comment on lines -44 to +52

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:



def _read_output(commandstring):
"""Output from successful command execution or None"""
Expand Down Expand Up @@ -334,7 +334,7 @@ def compiler_fixup(compiler_so, cc_args):
if 'ARCHFLAGS' in os.environ and not stripArch:
# 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)


if stripSysroot:
while True:
Expand Down Expand Up @@ -494,9 +494,5 @@ def get_platform_osx(_config_vars, osname, release, machine):
elif machine in ('PowerPC', 'Power_Macintosh'):
# Pick a sane name for the PPC architecture.
# See 'i386' case
if sys.maxsize >= 2**32:
machine = 'ppc64'
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:

return (osname, release, machine)
Loading