Skip to content

Commit 43025bd

Browse files
authored
Merge branch 'main' into asan
2 parents 6ffaace + 20b69aa commit 43025bd

32 files changed

Lines changed: 5635 additions & 105 deletions

Doc/c-api/type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ The following functions and structs are used to create
638638
under the :ref:`limited API <limited-c-api>`.
639639
640640
.. versionchanged:: 3.14
641-
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
641+
The field :c:member:`~PyTypeObject.tp_vectorcall` can now be set
642642
using :c:data:`Py_tp_vectorcall`. See the field's documentation
643643
for details.
644644

Doc/library/argparse.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,20 +1322,25 @@ attribute is determined by the ``dest`` keyword argument of
13221322

13231323
For optional argument actions, the value of ``dest`` is normally inferred from
13241324
the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
1325-
taking the first long option string and stripping away the initial ``--``
1326-
string. If no long option strings were supplied, ``dest`` will be derived from
1325+
taking the first double-dash long option string and stripping away the initial
1326+
``-`` characters.
1327+
If no double-dash long option strings were supplied, ``dest`` will be derived
1328+
from the first single-dash long option string by stripping the initial ``-``
1329+
character.
1330+
If no long option strings were supplied, ``dest`` will be derived from
13271331
the first short option string by stripping the initial ``-`` character. Any
13281332
internal ``-`` characters will be converted to ``_`` characters to make sure
13291333
the string is a valid attribute name. The examples below illustrate this
13301334
behavior::
13311335

13321336
>>> parser = argparse.ArgumentParser()
13331337
>>> parser.add_argument('-f', '--foo-bar', '--foo')
1338+
>>> parser.add_argument('-q', '-quz')
13341339
>>> parser.add_argument('-x', '-y')
1335-
>>> parser.parse_args('-f 1 -x 2'.split())
1336-
Namespace(foo_bar='1', x='2')
1337-
>>> parser.parse_args('--foo 1 -y 2'.split())
1338-
Namespace(foo_bar='1', x='2')
1340+
>>> parser.parse_args('-f 1 -q 2 -x 3'.split())
1341+
Namespace(foo_bar='1', quz='2', x='3')
1342+
>>> parser.parse_args('--foo 1 -quz 2 -y 3'.split())
1343+
Namespace(foo_bar='1', quz='2', x='2')
13391344

13401345
``dest`` allows a custom attribute name to be provided::
13411346

@@ -1344,6 +1349,9 @@ behavior::
13441349
>>> parser.parse_args('--foo XXX'.split())
13451350
Namespace(bar='XXX')
13461351

1352+
.. versionchanged:: next
1353+
Single-dash long option now takes precedence over short options.
1354+
13471355

13481356
.. _deprecated:
13491357

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,3 +1275,10 @@ that may require changes to your code.
12751275
Use its :meth:`!close` method or the :func:`contextlib.closing` context
12761276
manager to close it.
12771277
(Contributed by Osama Abdelkader and Serhiy Storchaka in :gh:`140601`.)
1278+
1279+
* If a short option and a single-dash long option are passed to
1280+
:meth:`argparse.ArgumentParser.add_argument`, *dest* is now inferred from
1281+
the single-dash long option. For example, in ``add_argument('-f', '-foo')``,
1282+
*dest* is now ``'foo'`` instead of ``'f'``.
1283+
Pass an explicit *dest* argument to preserve the old behavior.
1284+
(Contributed by Serhiy Storchaka in :gh:`138697`.)

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ struct _Py_global_strings {
793793
STRUCT_FOR_ID(symmetric_difference_update)
794794
STRUCT_FOR_ID(tabsize)
795795
STRUCT_FOR_ID(tag)
796+
STRUCT_FOR_ID(take_bytes)
796797
STRUCT_FOR_ID(target)
797798
STRUCT_FOR_ID(target_is_directory)
798799
STRUCT_FOR_ID(task)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/argparse.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,29 +1660,35 @@ def _get_positional_kwargs(self, dest, **kwargs):
16601660
def _get_optional_kwargs(self, *args, **kwargs):
16611661
# determine short and long option strings
16621662
option_strings = []
1663-
long_option_strings = []
16641663
for option_string in args:
16651664
# error on strings that don't start with an appropriate prefix
16661665
if not option_string[0] in self.prefix_chars:
16671666
raise ValueError(
16681667
f'invalid option string {option_string!r}: '
16691668
f'must start with a character {self.prefix_chars!r}')
1670-
1671-
# strings starting with two prefix characters are long options
16721669
option_strings.append(option_string)
1673-
if len(option_string) > 1 and option_string[1] in self.prefix_chars:
1674-
long_option_strings.append(option_string)
16751670

16761671
# infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
16771672
dest = kwargs.pop('dest', None)
16781673
if dest is None:
1679-
if long_option_strings:
1680-
dest_option_string = long_option_strings[0]
1681-
else:
1682-
dest_option_string = option_strings[0]
1683-
dest = dest_option_string.lstrip(self.prefix_chars)
1674+
priority = 0
1675+
for option_string in option_strings:
1676+
if len(option_string) <= 2:
1677+
# short option: '-x' -> 'x'
1678+
if priority < 1:
1679+
dest = option_string.lstrip(self.prefix_chars)
1680+
priority = 1
1681+
elif option_string[1] not in self.prefix_chars:
1682+
# single-dash long option: '-foo' -> 'foo'
1683+
if priority < 2:
1684+
dest = option_string.lstrip(self.prefix_chars)
1685+
priority = 2
1686+
else:
1687+
# two-dash long option: '--foo' -> 'foo'
1688+
dest = option_string.lstrip(self.prefix_chars)
1689+
break
16841690
if not dest:
1685-
msg = f'dest= is required for options like {option_string!r}'
1691+
msg = f'dest= is required for options like {repr(option_strings)[1:-1]}'
16861692
raise TypeError(msg)
16871693
dest = dest.replace('-', '_')
16881694

Lib/data.bin

12 KB
Binary file not shown.

Lib/profiling/sampling/collector.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from abc import ABC, abstractmethod
2-
3-
# Thread status flags
4-
try:
5-
from _remote_debugging import THREAD_STATUS_HAS_GIL, THREAD_STATUS_ON_CPU, THREAD_STATUS_UNKNOWN, THREAD_STATUS_GIL_REQUESTED
6-
except ImportError:
7-
# Fallback for tests or when module is not available
8-
THREAD_STATUS_HAS_GIL = (1 << 0)
9-
THREAD_STATUS_ON_CPU = (1 << 1)
10-
THREAD_STATUS_UNKNOWN = (1 << 2)
11-
THREAD_STATUS_GIL_REQUESTED = (1 << 3)
2+
from .constants import (
3+
THREAD_STATUS_HAS_GIL,
4+
THREAD_STATUS_ON_CPU,
5+
THREAD_STATUS_UNKNOWN,
6+
THREAD_STATUS_GIL_REQUESTED,
7+
)
128

139
class Collector(ABC):
1410
@abstractmethod
1511
def collect(self, stack_frames):
1612
"""Collect profiling data from stack frames."""
1713

14+
def collect_failed_sample(self):
15+
"""Collect data about a failed sample attempt."""
16+
1817
@abstractmethod
1918
def export(self, filename):
2019
"""Export collected data to a file."""

0 commit comments

Comments
 (0)