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
4 changes: 1 addition & 3 deletions Lib/__future__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def getMandatoryRelease(self):
return self.mandatory

def __repr__(self):
return "_Feature" + repr((self.optional,
self.mandatory,
self.compiler_flag))
return f"_Feature{repr((self.optional, self.mandatory, self.compiler_flag))}"
Copy link
Author

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:



nested_scopes = _Feature((2, 1, 0, "beta", 1),
Expand Down
64 changes: 16 additions & 48 deletions Lib/_collections_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Hashable.__subclasshook__ refactored with the following changes:



class Awaitable(metaclass=ABCMeta):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Awaitable.__subclasshook__ refactored with the following changes:


__class_getitem__ = classmethod(GenericAlias)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Iterable.__subclasshook__ refactored with the following changes:


__class_getitem__ = classmethod(GenericAlias)

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Sized.__subclasshook__ refactored with the following changes:



class Container(metaclass=ABCMeta):
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function _CallableGenericAlias.__parameters__ refactored with the following changes:

return tuple(dict.fromkeys(params))

def __repr__(self):
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function _CallableGenericAlias.__getitem__ refactored with the following changes:

This removes the following comments ( why? ):

# Looks like a GenericAlias

subargs = tuple(subst[x] for x in subparams)
arg = arg[subargs]
new_args.append(arg)
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function _type_repr refactored with the following changes:



class Callable(metaclass=ABCMeta):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Callable.__subclasshook__ refactored with the following changes:


__class_getitem__ = classmethod(_CallableGenericAlias)

Expand All @@ -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
Copy link
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 @@ -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
Copy link
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 @@ -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
Copy link
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 @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function KeysView._from_iterable refactored with the following changes:

return set(it)

def __contains__(self, key):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function ItemsView._from_iterable refactored with the following changes:

return set(it)

def __contains__(self, item):
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function Sequence.__iter__ refactored with the following changes:

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
Copy link
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
58 changes: 35 additions & 23 deletions Lib/_compat_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Lines 173-232 refactored with the following changes:

'cPickle': 'pickle',
'_elementtree': 'xml.etree.ElementTree',
'FileDialog': 'tkinter.filedialog',
Expand All @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions Lib/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Author

Choose a reason for hiding this comment

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

Function DecompressReader.seek refactored with the following changes:


# Make it so that offset is the number of bytes to skip forward.
if offset < self._pos:
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions Lib/_dummy_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function fspath refactored with the following changes:


class PathLike(abc.ABC):

Expand Down
43 changes: 16 additions & 27 deletions Lib/_dummy_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({}):
Copy link
Author

Choose a reason for hiding this comment

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

Function start_new_thread refactored with the following changes:

raise TypeError("3rd arg must be a dict")
global _main
_main = False
Expand Down Expand Up @@ -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
Copy link
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 All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function LockType.__repr__ refactored with the following changes:


# Used to signal that interrupt_main was called in a "thread"
_interrupt = False
Expand All @@ -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
Copy link
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:


class RLock:
def __init__(self):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function RLock.__repr__ refactored with the following changes:

Loading