-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored Tapuzi/cpython #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,8 +106,7 @@ def test(): | |
| try: | ||
| x = next(it) | ||
| except ZeroDivisionError: | ||
| if i == 5: | ||
| pass | ||
| pass | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| except StopIteration: | ||
| break | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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') | ||
|
|
||
|
|
||
|
|
||
| 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)} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| con = sqlite3.connect(":memory:") | ||
| con.row_factory = dict_factory | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
|
||
| DSTDIFF = DSTOFFSET - STDOFFSET | ||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| dststart, dstend = DSTSTART_2007, DSTEND_2007 | ||
| elif 1986 < year < 2007: | ||
| dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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*"): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| continue | ||
| if entry.result_refs is None: | ||
| rc = 'Return value: Always NULL.' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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. | ||
|
|
@@ -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') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def __lt__(self, other): | ||
| if not isinstance(other, Set): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def __eq__(self, other): | ||
| if not isinstance(other, Set): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def __or__(self, other): | ||
| if not isinstance(other, Iterable): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def __reversed__(self): | ||
| for i in reversed(range(len(self))): | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| Sequence.register(tuple) | ||
| Sequence.register(str) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| assert len(REVERSE_NAME_MAPPING) == len(NAME_MAPPING) | ||
|
|
||
| # Non-mutual mappings. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| __enter__ = acquire | ||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| elif c.isspace(): | ||
| j = j + 1 | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def _read_output(commandstring): | ||
| """Output from successful command execution or None""" | ||
|
|
@@ -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() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| if stripSysroot: | ||
| while True: | ||
|
|
@@ -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' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return (osname, release, machine) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
getTextrefactored with the following changes:list-comprehension)