-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #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: main
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 |
---|---|---|
|
@@ -97,9 +97,7 @@ def __hash__(self): | |
|
||
@classmethod | ||
def __subclasshook__(cls, C): | ||
if cls is Hashable: | ||
return _check_methods(C, "__hash__") | ||
return NotImplemented | ||
return _check_methods(C, "__hash__") if cls is Hashable else NotImplemented | ||
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
|
||
|
||
|
||
class Awaitable(metaclass=ABCMeta): | ||
|
@@ -112,9 +110,7 @@ def __await__(self): | |
|
||
@classmethod | ||
def __subclasshook__(cls, C): | ||
if cls is Awaitable: | ||
return _check_methods(C, "__await__") | ||
return NotImplemented | ||
return _check_methods(C, "__await__") if cls is Awaitable else NotImplemented | ||
Comment on lines
-115
to
+113
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
|
||
|
||
__class_getitem__ = classmethod(GenericAlias) | ||
|
||
|
@@ -261,9 +257,7 @@ def __iter__(self): | |
|
||
@classmethod | ||
def __subclasshook__(cls, C): | ||
if cls is Iterable: | ||
return _check_methods(C, "__iter__") | ||
return NotImplemented | ||
return _check_methods(C, "__iter__") if cls is Iterable else NotImplemented | ||
Comment on lines
-264
to
+260
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
|
||
|
||
__class_getitem__ = classmethod(GenericAlias) | ||
|
||
|
@@ -380,9 +374,7 @@ def __len__(self): | |
|
||
@classmethod | ||
def __subclasshook__(cls, C): | ||
if cls is Sized: | ||
return _check_methods(C, "__len__") | ||
return NotImplemented | ||
return _check_methods(C, "__len__") if cls is Sized else NotImplemented | ||
Comment on lines
-383
to
+377
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
|
||
|
||
|
||
class Container(metaclass=ABCMeta): | ||
|
@@ -444,9 +436,8 @@ def __parameters__(self): | |
# Looks like a genericalias | ||
if hasattr(arg, "__parameters__") and isinstance(arg.__parameters__, tuple): | ||
params.extend(arg.__parameters__) | ||
else: | ||
if _is_typevarlike(arg): | ||
params.append(arg) | ||
elif _is_typevarlike(arg): | ||
params.append(arg) | ||
Comment on lines
-447
to
+440
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 tuple(dict.fromkeys(params)) | ||
|
||
def __repr__(self): | ||
|
@@ -494,10 +485,8 @@ def __getitem__(self, item): | |
f"ParamSpec, or Concatenate. Got {arg}") | ||
else: | ||
arg = subst[arg] | ||
# Looks like a GenericAlias | ||
elif hasattr(arg, '__parameters__') and isinstance(arg.__parameters__, tuple): | ||
subparams = arg.__parameters__ | ||
if subparams: | ||
if subparams := arg.__parameters__: | ||
Comment on lines
-497
to
+489
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
This removes the following comments ( why? ):
|
||
subargs = tuple(subst[x] for x in subparams) | ||
arg = arg[subargs] | ||
new_args.append(arg) | ||
|
@@ -542,9 +531,7 @@ def _type_repr(obj): | |
return f'{obj.__module__}.{obj.__qualname__}' | ||
if obj is Ellipsis: | ||
return '...' | ||
if isinstance(obj, FunctionType): | ||
return obj.__name__ | ||
return repr(obj) | ||
return obj.__name__ if isinstance(obj, FunctionType) else repr(obj) | ||
Comment on lines
-545
to
+534
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
|
||
|
||
|
||
class Callable(metaclass=ABCMeta): | ||
|
@@ -557,9 +544,7 @@ def __call__(self, *args, **kwds): | |
|
||
@classmethod | ||
def __subclasshook__(cls, C): | ||
if cls is Callable: | ||
return _check_methods(C, "__call__") | ||
return NotImplemented | ||
return _check_methods(C, "__call__") if cls is Callable else NotImplemented | ||
Comment on lines
-560
to
+547
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
|
||
|
||
__class_getitem__ = classmethod(_CallableGenericAlias) | ||
|
||
|
@@ -583,12 +568,7 @@ class Set(Collection): | |
def __le__(self, other): | ||
if not isinstance(other, Set): | ||
return NotImplemented | ||
if len(self) > len(other): | ||
return False | ||
for elem in self: | ||
if elem not in other: | ||
return False | ||
return True | ||
return False if len(self) > len(other) else all(elem in other for elem in self) | ||
Comment on lines
-586
to
+571
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): | ||
|
@@ -603,12 +583,7 @@ def __gt__(self, other): | |
def __ge__(self, other): | ||
if not isinstance(other, Set): | ||
return NotImplemented | ||
if len(self) < len(other): | ||
return False | ||
for elem in other: | ||
if elem not in self: | ||
return False | ||
return True | ||
return False if len(self) < len(other) else all(elem in self for elem in other) | ||
Comment on lines
-606
to
+586
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): | ||
|
@@ -633,10 +608,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
-636
to
+611
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): | ||
|
@@ -868,7 +840,7 @@ class KeysView(MappingView, Set): | |
__slots__ = () | ||
|
||
@classmethod | ||
def _from_iterable(self, it): | ||
def _from_iterable(cls, it): | ||
Comment on lines
-871
to
+843
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 set(it) | ||
|
||
def __contains__(self, key): | ||
|
@@ -886,7 +858,7 @@ class ItemsView(MappingView, Set): | |
__slots__ = () | ||
|
||
@classmethod | ||
def _from_iterable(self, it): | ||
def _from_iterable(cls, it): | ||
Comment on lines
-889
to
+861
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 set(it) | ||
|
||
def __contains__(self, item): | ||
|
@@ -1032,17 +1004,13 @@ def __iter__(self): | |
i = 0 | ||
try: | ||
while True: | ||
v = self[i] | ||
yield v | ||
yield self[i] | ||
Comment on lines
-1035
to
+1007
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
|
||
i += 1 | ||
except IndexError: | ||
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
-1042
to
+1013
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))): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,14 +170,14 @@ | |
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()} | ||
assert len(REVERSE_NAME_MAPPING) == len(NAME_MAPPING) | ||
|
||
# Non-mutual mappings. | ||
|
||
IMPORT_MAPPING.update({ | ||
IMPORT_MAPPING |= { | ||
Comment on lines
-173
to
+180
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
|
||
'cPickle': 'pickle', | ||
'_elementtree': 'xml.etree.ElementTree', | ||
'FileDialog': 'tkinter.filedialog', | ||
|
@@ -190,46 +190,58 @@ | |
'UserList': 'collections', | ||
'UserString': 'collections', | ||
'whichdb': 'dbm', | ||
'StringIO': 'io', | ||
'StringIO': 'io', | ||
'cStringIO': 'io', | ||
}) | ||
} | ||
|
||
REVERSE_IMPORT_MAPPING.update({ | ||
REVERSE_IMPORT_MAPPING |= { | ||
'_bz2': 'bz2', | ||
'_dbm': 'dbm', | ||
'_functools': 'functools', | ||
'_gdbm': 'gdbm', | ||
'_pickle': 'pickle', | ||
}) | ||
} | ||
|
||
NAME_MAPPING.update({ | ||
NAME_MAPPING |= { | ||
('__builtin__', 'basestring'): ('builtins', 'str'), | ||
('exceptions', 'StandardError'): ('builtins', 'Exception'), | ||
('UserDict', 'UserDict'): ('collections', 'UserDict'), | ||
('socket', '_socketobject'): ('socket', 'SocketType'), | ||
}) | ||
} | ||
|
||
REVERSE_NAME_MAPPING.update({ | ||
REVERSE_NAME_MAPPING |= { | ||
('_functools', 'reduce'): ('__builtin__', 'reduce'), | ||
('tkinter.filedialog', 'FileDialog'): ('FileDialog', 'FileDialog'), | ||
('tkinter.filedialog', 'LoadFileDialog'): ('FileDialog', 'LoadFileDialog'), | ||
('tkinter.filedialog', 'SaveFileDialog'): ('FileDialog', 'SaveFileDialog'), | ||
('tkinter.simpledialog', 'SimpleDialog'): ('SimpleDialog', 'SimpleDialog'), | ||
('xmlrpc.server', 'ServerHTMLDoc'): ('DocXMLRPCServer', 'ServerHTMLDoc'), | ||
('xmlrpc.server', 'XMLRPCDocGenerator'): | ||
('DocXMLRPCServer', 'XMLRPCDocGenerator'), | ||
('xmlrpc.server', 'DocXMLRPCRequestHandler'): | ||
('DocXMLRPCServer', 'DocXMLRPCRequestHandler'), | ||
('xmlrpc.server', 'DocXMLRPCServer'): | ||
('DocXMLRPCServer', 'DocXMLRPCServer'), | ||
('xmlrpc.server', 'DocCGIXMLRPCRequestHandler'): | ||
('DocXMLRPCServer', 'DocCGIXMLRPCRequestHandler'), | ||
('http.server', 'SimpleHTTPRequestHandler'): | ||
('SimpleHTTPServer', 'SimpleHTTPRequestHandler'), | ||
('http.server', 'CGIHTTPRequestHandler'): | ||
('CGIHTTPServer', 'CGIHTTPRequestHandler'), | ||
('xmlrpc.server', 'XMLRPCDocGenerator'): ( | ||
'DocXMLRPCServer', | ||
'XMLRPCDocGenerator', | ||
), | ||
('xmlrpc.server', 'DocXMLRPCRequestHandler'): ( | ||
'DocXMLRPCServer', | ||
'DocXMLRPCRequestHandler', | ||
), | ||
('xmlrpc.server', 'DocXMLRPCServer'): ( | ||
'DocXMLRPCServer', | ||
'DocXMLRPCServer', | ||
), | ||
('xmlrpc.server', 'DocCGIXMLRPCRequestHandler'): ( | ||
'DocXMLRPCServer', | ||
'DocCGIXMLRPCRequestHandler', | ||
), | ||
('http.server', 'SimpleHTTPRequestHandler'): ( | ||
'SimpleHTTPServer', | ||
'SimpleHTTPRequestHandler', | ||
), | ||
('http.server', 'CGIHTTPRequestHandler'): ( | ||
'CGIHTTPServer', | ||
'CGIHTTPRequestHandler', | ||
), | ||
('_socket', 'socket'): ('socket', '_socketobject'), | ||
}) | ||
} | ||
|
||
PYTHON3_OSERROR_EXCEPTIONS = ( | ||
'BrokenPipeError', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ def seek(self, offset, whence=io.SEEK_SET): | |
pass | ||
offset = self._size + offset | ||
else: | ||
raise ValueError("Invalid value for whence: {}".format(whence)) | ||
raise ValueError(f"Invalid value for whence: {whence}") | ||
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
|
||
|
||
# Make it so that offset is the number of bytes to skip forward. | ||
if offset < self._pos: | ||
|
@@ -150,11 +150,11 @@ def seek(self, offset, whence=io.SEEK_SET): | |
|
||
# Read and discard data until we reach the desired position. | ||
while offset > 0: | ||
data = self.read(min(io.DEFAULT_BUFFER_SIZE, offset)) | ||
if not data: | ||
break | ||
offset -= len(data) | ||
if data := self.read(min(io.DEFAULT_BUFFER_SIZE, offset)): | ||
offset -= len(data) | ||
|
||
else: | ||
break | ||
return self._pos | ||
|
||
def tell(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,9 +48,9 @@ def fspath(path): | |
if isinstance(path_repr, (str, bytes)): | ||
return path_repr | ||
else: | ||
raise TypeError("expected {}.__fspath__() to return str or bytes, " | ||
"not {}".format(path_type.__name__, | ||
type(path_repr).__name__)) | ||
raise TypeError( | ||
f"expected {path_type.__name__}.__fspath__() to return str or bytes, not {type(path_repr).__name__}" | ||
) | ||
Comment on lines
-51
to
+53
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
|
||
|
||
class PathLike(abc.ABC): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ def start_new_thread(function, args, kwargs={}): | |
""" | ||
if type(args) != type(tuple()): | ||
raise TypeError("2nd arg must be a tuple") | ||
if type(kwargs) != type(dict()): | ||
if type(kwargs) != type({}): | ||
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
|
||
raise TypeError("3rd arg must be a dict") | ||
global _main | ||
_main = False | ||
|
@@ -115,18 +115,20 @@ def acquire(self, waitflag=None, timeout=-1): | |
aren't triggered and throw a little fit. | ||
|
||
""" | ||
if waitflag is None or waitflag: | ||
if ( | ||
waitflag is not None | ||
and not waitflag | ||
and 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
-118
to
+131
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 | ||
|
||
|
@@ -149,12 +151,7 @@ def _at_fork_reinit(self): | |
self.locked_status = False | ||
|
||
def __repr__(self): | ||
return "<%s %s.%s object at %s>" % ( | ||
"locked" if self.locked_status else "unlocked", | ||
self.__class__.__module__, | ||
self.__class__.__qualname__, | ||
hex(id(self)) | ||
) | ||
return f'<{"locked" if self.locked_status else "unlocked"} {self.__class__.__module__}.{self.__class__.__qualname__} object at {hex(id(self))}>' | ||
Comment on lines
-152
to
+154
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
|
||
|
||
# Used to signal that interrupt_main was called in a "thread" | ||
_interrupt = False | ||
|
@@ -166,9 +163,8 @@ def interrupt_main(): | |
KeyboardInterrupt upon exiting.""" | ||
if _main: | ||
raise KeyboardInterrupt | ||
else: | ||
global _interrupt | ||
_interrupt = True | ||
global _interrupt | ||
_interrupt = True | ||
Comment on lines
-169
to
+167
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
|
||
|
||
class RLock: | ||
def __init__(self): | ||
|
@@ -193,11 +189,4 @@ def locked(self): | |
return self.locked_status != 0 | ||
|
||
def __repr__(self): | ||
return "<%s %s.%s object owner=%s count=%s at %s>" % ( | ||
"locked" if self.locked_count else "unlocked", | ||
self.__class__.__module__, | ||
self.__class__.__qualname__, | ||
get_ident() if self.locked_count else 0, | ||
self.locked_count, | ||
hex(id(self)) | ||
) | ||
return f'<{"locked" if self.locked_count else "unlocked"} {self.__class__.__module__}.{self.__class__.__qualname__} object owner={get_ident() if self.locked_count else 0} count={self.locked_count} at {hex(id(self))}>' | ||
Comment on lines
-196
to
+192
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
|
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
_Feature.__repr__
refactored with the following changes:use-fstring-for-concatenation
)