Skip to content

Commit

Permalink
Update Python 3 from 3.11.2 to 3.11.3
Browse files Browse the repository at this point in the history
  • Loading branch information
shadchin committed Apr 18, 2023
1 parent 24bd1c2 commit f30f788
Show file tree
Hide file tree
Showing 50 changed files with 479 additions and 481 deletions.
4 changes: 2 additions & 2 deletions contrib/tools/python3/src/Include/patchlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
/*--start constants--*/
#define PY_MAJOR_VERSION 3
#define PY_MINOR_VERSION 11
#define PY_MICRO_VERSION 2
#define PY_MICRO_VERSION 3
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_FINAL
#define PY_RELEASE_SERIAL 0

/* Version as a string */
#define PY_VERSION "3.11.2"
#define PY_VERSION "3.11.3"
/*--end constants--*/

/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
Expand Down
13 changes: 10 additions & 3 deletions contrib/tools/python3/src/Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,18 @@ def _format_actions_usage(self, actions, groups):
except ValueError:
continue
else:
end = start + len(group._group_actions)
group_action_count = len(group._group_actions)
end = start + group_action_count
if actions[start:end] == group._group_actions:

suppressed_actions_count = 0
for action in group._group_actions:
group_actions.add(action)
if action.help is SUPPRESS:
suppressed_actions_count += 1

exposed_actions_count = group_action_count - suppressed_actions_count

if not group.required:
if start in inserts:
inserts[start] += ' ['
Expand All @@ -416,7 +424,7 @@ def _format_actions_usage(self, actions, groups):
inserts[end] += ']'
else:
inserts[end] = ']'
else:
elif exposed_actions_count > 1:
if start in inserts:
inserts[start] += ' ('
else:
Expand Down Expand Up @@ -490,7 +498,6 @@ def _format_actions_usage(self, actions, groups):
text = _re.sub(r'(%s) ' % open, r'\1', text)
text = _re.sub(r' (%s)' % close, r'\1', text)
text = _re.sub(r'%s *%s' % (open, close), r'', text)
text = _re.sub(r'\(([^|]*)\)', r'\1', text)
text = text.strip()

# return the text
Expand Down
17 changes: 9 additions & 8 deletions contrib/tools/python3/src/Lib/asyncio/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,17 @@ async def readuntil(self, separator=b'\n'):
async def read(self, n=-1):
"""Read up to `n` bytes from the stream.
If n is not provided, or set to -1, read until EOF and return all read
bytes. If the EOF was received and the internal buffer is empty, return
an empty bytes object.
If `n` is not provided or set to -1,
read until EOF, then return all read bytes.
If EOF was received and the internal buffer is empty,
return an empty bytes object.
If n is zero, return empty bytes object immediately.
If `n` is 0, return an empty bytes object immediately.
If n is positive, this function try to read `n` bytes, and may return
less or equal bytes than requested, but at least one byte. If EOF was
received before any byte is read, this function returns empty byte
object.
If `n` is positive, return at most `n` available bytes
as soon as at least 1 byte is available in the internal buffer.
If EOF is received before any byte is read, return an empty
bytes object.
Returned value is not limited with limit, configured at stream
creation.
Expand Down
18 changes: 18 additions & 0 deletions contrib/tools/python3/src/Lib/asyncio/taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@


class TaskGroup:
"""Asynchronous context manager for managing groups of tasks.
Example use:
async with asyncio.TaskGroup() as group:
task1 = group.create_task(some_coroutine(...))
task2 = group.create_task(other_coroutine(...))
print("Both tasks have completed now.")
All tasks are awaited when the context manager exits.
Any exceptions other than `asyncio.CancelledError` raised within
a task will cancel all remaining tasks and wait for them to exit.
The exceptions are then combined and raised as an `ExceptionGroup`.
"""
def __init__(self):
self._entered = False
self._exiting = False
Expand Down Expand Up @@ -135,6 +149,10 @@ async def __aexit__(self, et, exc, tb):
self._errors = None

def create_task(self, coro, *, name=None, context=None):
"""Create a new task in this group and return it.
Similar to `asyncio.create_task`.
"""
if not self._entered:
raise RuntimeError(f"TaskGroup {self!r} has not been entered")
if self._exiting and not self._tasks:
Expand Down
19 changes: 16 additions & 3 deletions contrib/tools/python3/src/Lib/asyncio/timeouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,30 @@ class _State(enum.Enum):

@final
class Timeout:
"""Asynchronous context manager for cancelling overdue coroutines.
Use `timeout()` or `timeout_at()` rather than instantiating this class directly.
"""

def __init__(self, when: Optional[float]) -> None:
"""Schedule a timeout that will trigger at a given loop time.
- If `when` is `None`, the timeout will never trigger.
- If `when < loop.time()`, the timeout will trigger on the next
iteration of the event loop.
"""
self._state = _State.CREATED

self._timeout_handler: Optional[events.TimerHandle] = None
self._task: Optional[tasks.Task] = None
self._when = when

def when(self) -> Optional[float]:
"""Return the current deadline."""
return self._when

def reschedule(self, when: Optional[float]) -> None:
"""Reschedule the timeout."""
assert self._state is not _State.CREATED
if self._state is not _State.ENTERED:
raise RuntimeError(
Expand Down Expand Up @@ -72,6 +84,7 @@ def __repr__(self) -> str:
async def __aenter__(self) -> "Timeout":
self._state = _State.ENTERED
self._task = tasks.current_task()
self._cancelling = self._task.cancelling()
if self._task is None:
raise RuntimeError("Timeout should be used inside a task")
self.reschedule(self._when)
Expand All @@ -92,10 +105,10 @@ async def __aexit__(
if self._state is _State.EXPIRING:
self._state = _State.EXPIRED

if self._task.uncancel() == 0 and exc_type is exceptions.CancelledError:
# Since there are no outstanding cancel requests, we're
if self._task.uncancel() <= self._cancelling and exc_type is exceptions.CancelledError:
# Since there are no new cancel requests, we're
# handling this.
raise TimeoutError
raise TimeoutError from exc_val
elif self._state is _State.ENTERED:
self._state = _State.EXITED

Expand Down
7 changes: 4 additions & 3 deletions contrib/tools/python3/src/Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ def format_stack_entry(self, frame_lineno, lprefix=': '):
rv = frame.f_locals['__return__']
s += '->'
s += reprlib.repr(rv)
line = linecache.getline(filename, lineno, frame.f_globals)
if line:
s += lprefix + line.strip()
if lineno is not None:
line = linecache.getline(filename, lineno, frame.f_globals)
if line:
s += lprefix + line.strip()
return s

# The following methods can be called by clients to use
Expand Down
5 changes: 5 additions & 0 deletions contrib/tools/python3/src/Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ def run(self):
if self.is_shutting_down():
self.flag_executor_shutting_down()

# When only canceled futures remain in pending_work_items, our
# next call to wait_result_broken_or_wakeup would hang forever.
# This makes sure we have some running futures or none at all.
self.add_call_item_to_queue()

# Since no new work items can be added, it is safe to shutdown
# this thread if there are no pending work items.
if not self.pending_work_items:
Expand Down
5 changes: 4 additions & 1 deletion contrib/tools/python3/src/Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,9 @@ def _add_slots(cls, is_frozen, weakref_slot):
# Remove __dict__ itself.
cls_dict.pop('__dict__', None)

# Clear existing `__weakref__` descriptor, it belongs to a previous type:
cls_dict.pop('__weakref__', None) # gh-102069

# And finally create the class.
qualname = getattr(cls, '__qualname__', None)
cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
Expand Down Expand Up @@ -1231,7 +1234,7 @@ def fields(class_or_instance):
try:
fields = getattr(class_or_instance, _FIELDS)
except AttributeError:
raise TypeError('must be called with a dataclass type or instance')
raise TypeError('must be called with a dataclass type or instance') from None

# Exclude pseudo-fields. Note that fields is sorted by insertion
# order, so the order of the tuple is as the fields were defined.
Expand Down
43 changes: 20 additions & 23 deletions contrib/tools/python3/src/Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,20 @@ def __set_name__(self, enum_class, member_name):
args = (args, ) # wrap it one more time
if not enum_class._use_args_:
enum_member = enum_class._new_member_(enum_class)
if not hasattr(enum_member, '_value_'):
else:
enum_member = enum_class._new_member_(enum_class, *args)
if not hasattr(enum_member, '_value_'):
if enum_class._member_type_ is object:
enum_member._value_ = value
else:
try:
enum_member._value_ = enum_class._member_type_(*args)
except Exception as exc:
enum_member._value_ = value
else:
enum_member = enum_class._new_member_(enum_class, *args)
if not hasattr(enum_member, '_value_'):
if enum_class._member_type_ is object:
enum_member._value_ = value
else:
try:
enum_member._value_ = enum_class._member_type_(*args)
except Exception as exc:
raise TypeError(
'_value_ not set in __new__, unable to create it'
) from None
new_exc = TypeError(
'_value_ not set in __new__, unable to create it'
)
new_exc.__cause__ = exc
raise new_exc
value = enum_member._value_
enum_member._name_ = member_name
enum_member.__objclass__ = enum_class
Expand Down Expand Up @@ -936,7 +933,7 @@ def _convert_(cls, name, module, filter, source=None, *, boundary=None, as_globa
def _check_for_existing_members_(mcls, class_name, bases):
for chain in bases:
for base in chain.__mro__:
if issubclass(base, Enum) and base._member_names_:
if isinstance(base, EnumType) and base._member_names_:
raise TypeError(
"<enum %r> cannot extend %r"
% (class_name, base)
Expand All @@ -958,7 +955,7 @@ def _get_mixins_(mcls, class_name, bases):
# ensure final parent class is an Enum derivative, find any concrete
# data type, and check that Enum has no members
first_enum = bases[-1]
if not issubclass(first_enum, Enum):
if not isinstance(first_enum, EnumType):
raise TypeError("new enumerations should be created as "
"`EnumName([mixin_type, ...] [data_type,] enum_type)`")
member_type = mcls._find_data_type_(class_name, bases) or object
Expand All @@ -970,7 +967,7 @@ def _find_data_repr_(mcls, class_name, bases):
for base in chain.__mro__:
if base is object:
continue
elif issubclass(base, Enum):
elif isinstance(base, EnumType):
# if we hit an Enum, use it's _value_repr_
return base._value_repr_
elif '__repr__' in base.__dict__:
Expand All @@ -988,12 +985,12 @@ def _find_data_type_(mcls, class_name, bases):
base_chain.add(base)
if base is object:
continue
elif issubclass(base, Enum):
elif isinstance(base, EnumType):
if base._member_type_ is not object:
data_types.add(base._member_type_)
break
elif '__new__' in base.__dict__ or '__init__' in base.__dict__:
if issubclass(base, Enum):
if isinstance(base, EnumType):
continue
data_types.add(candidate or base)
break
Expand Down Expand Up @@ -1302,10 +1299,10 @@ def _reduce_ex_by_global_name(self, proto):
class FlagBoundary(StrEnum):
"""
control how out of range values are handled
"strict" -> error is raised [default for Flag]
"conform" -> extra bits are discarded
"eject" -> lose flag status [default for IntFlag]
"keep" -> keep flag status and all bits
"strict" -> error is raised
"conform" -> extra bits are discarded [default for Flag]
"eject" -> lose flag status
"keep" -> keep flag status and all bits [default for IntFlag]
"""
STRICT = auto()
CONFORM = auto()
Expand Down
2 changes: 1 addition & 1 deletion contrib/tools/python3/src/Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def isstdin(self):


def hook_compressed(filename, mode, *, encoding=None, errors=None):
if encoding is None: # EncodingWarning is emitted in FileInput() already.
if encoding is None and "b" not in mode: # EncodingWarning is emitted in FileInput() already.
encoding = "locale"
ext = os.path.splitext(filename)[1]
if ext == '.gz':
Expand Down
2 changes: 1 addition & 1 deletion contrib/tools/python3/src/Lib/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def escape(s, quote=True):
return s


# see http://www.w3.org/TR/html5/syntax.html#tokenizing-character-references
# see https://html.spec.whatwg.org/multipage/parsing.html#numeric-character-reference-end-state

_invalid_charrefs = {
0x00: '\ufffd', # REPLACEMENT CHARACTER
Expand Down
1 change: 1 addition & 0 deletions contrib/tools/python3/src/Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def isclosed(self):
return self.fp is None

def read(self, amt=None):
"""Read and return the response body, or up to the next amt bytes."""
if self.fp is None:
return b""

Expand Down
13 changes: 2 additions & 11 deletions contrib/tools/python3/src/Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ def find_function(funcname, filename):
return funcname, filename, lineno
return None

def getsourcelines(obj):
lines, lineno = inspect.findsource(obj)
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
# must be a module frame: do not try to cut a block out of it
return lines, 1
elif inspect.ismodule(obj):
return lines, 1
return inspect.getblock(lines[lineno:]), lineno+1

def lasti2lineno(code, lasti):
linestarts = list(dis.findlinestarts(code))
linestarts.reverse()
Expand Down Expand Up @@ -1357,7 +1348,7 @@ def do_longlist(self, arg):
filename = self.curframe.f_code.co_filename
breaklist = self.get_file_breaks(filename)
try:
lines, lineno = getsourcelines(self.curframe)
lines, lineno = inspect.getsourcelines(self.curframe)
except OSError as err:
self.error(err)
return
Expand All @@ -1373,7 +1364,7 @@ def do_source(self, arg):
except:
return
try:
lines, lineno = getsourcelines(obj)
lines, lineno = inspect.getsourcelines(obj)
except (OSError, TypeError) as err:
self.error(err)
return
Expand Down
Loading

0 comments on commit f30f788

Please sign in to comment.