Skip to content

Commit 324bcfd

Browse files
Merge branch 'main' into test-ioctl2
2 parents 86887c9 + 8c975b0 commit 324bcfd

File tree

22 files changed

+182
-47
lines changed

22 files changed

+182
-47
lines changed

Doc/c-api/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ complete listing.
148148
.. c:macro:: Py_ALWAYS_INLINE
149149
150150
Ask the compiler to always inline a static inline function. The compiler can
151-
ignore it and decides to not inline the function.
151+
ignore it and decide to not inline the function.
152152

153153
It can be used to inline performance critical static inline functions when
154154
building Python in debug mode with function inlining disabled. For example,

Doc/library/decimal.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ Decimal objects
367367
appears above. These include decimal digits from various other
368368
alphabets (for example, Arabic-Indic and Devanāgarī digits) along
369369
with the fullwidth digits ``'\uff10'`` through ``'\uff19'``.
370+
Case is not significant, so, for example, ``inf``, ``Inf``, ``INFINITY``,
371+
and ``iNfINity`` are all acceptable spellings for positive infinity.
370372

371373
If *value* is a :class:`tuple`, it should have three components, a sign
372374
(``0`` for positive or ``1`` for negative), a :class:`tuple` of

Doc/library/webbrowser.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ Here are some simple examples::
226226
Browser Controller Objects
227227
--------------------------
228228

229-
Browser controllers provide these methods which parallel three of the
230-
module-level convenience functions:
229+
Browser controllers provide the :attr:`~controller.name` attribute,
230+
and the following three methods which parallel module-level convenience functions:
231231

232232

233233
.. attribute:: controller.name

Doc/reference/datamodel.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,18 +1526,17 @@ positional arguments; bit ``0x08`` is set if the function uses the
15261526
if the function is a generator. See :ref:`inspect-module-co-flags` for details
15271527
on the semantics of each flags that might be present.
15281528

1529-
Future feature declarations (``from __future__ import division``) also use bits
1529+
Future feature declarations (for example, ``from __future__ import division``) also use bits
15301530
in :attr:`~codeobject.co_flags` to indicate whether a code object was compiled with a
1531-
particular feature enabled: bit ``0x2000`` is set if the function was compiled
1532-
with future division enabled; bits ``0x10`` and ``0x1000`` were used in earlier
1533-
versions of Python.
1531+
particular feature enabled. See :attr:`~__future__._Feature.compiler_flag`.
15341532

15351533
Other bits in :attr:`~codeobject.co_flags` are reserved for internal use.
15361534

15371535
.. index:: single: documentation string
15381536

15391537
If a code object represents a function and has a docstring,
1540-
the first item in :attr:`~codeobject.co_consts` is
1538+
the :data:`~inspect.CO_HAS_DOCSTRING` bit is set in :attr:`~codeobject.co_flags`
1539+
and the first item in :attr:`~codeobject.co_consts` is
15411540
the docstring of the function.
15421541

15431542
Methods on code objects

InternalDocs/garbage_collector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ superset of any unreachable cycle including that object, we are guaranteed that
417417
transitive closure cannot contain any partial cycles.
418418
We can exclude scanned objects, as they must have been reachable when scanned.
419419
If a scanned object becomes part of an unreachable cycle after being scanned, it will
420-
not be collected this at this time, but it will be collected in the next full scavenge.
420+
not be collected at this time, but it will be collected in the next full scavenge.
421421

422422
> [!NOTE]
423423
> The GC implementation for the free-threaded build does not use incremental collection.

Lib/_pydatetime.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,12 @@ def fromordinal(cls, n):
10501050
@classmethod
10511051
def fromisoformat(cls, date_string):
10521052
"""Construct a date from a string in ISO 8601 format."""
1053+
10531054
if not isinstance(date_string, str):
1054-
raise TypeError('fromisoformat: argument must be str')
1055+
raise TypeError('Argument must be a str')
1056+
1057+
if not date_string.isascii():
1058+
raise ValueError('Argument must be an ASCII str')
10551059

10561060
if len(date_string) not in (7, 8, 10):
10571061
raise ValueError(f'Invalid isoformat string: {date_string!r}')

Lib/shlex.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
# iterator interface by Gustavo Niemeyer, April 2003.
88
# changes to tokenize more like Posix shells by Vinay Sajip, July 2016.
99

10-
import os
11-
import re
1210
import sys
13-
from collections import deque
14-
1511
from io import StringIO
1612

1713
__all__ = ["shlex", "split", "quote", "join"]
@@ -20,6 +16,8 @@ class shlex:
2016
"A lexical analyzer class for simple shell-like syntaxes."
2117
def __init__(self, instream=None, infile=None, posix=False,
2218
punctuation_chars=False):
19+
from collections import deque # deferred import for performance
20+
2321
if isinstance(instream, str):
2422
instream = StringIO(instream)
2523
if instream is not None:
@@ -278,6 +276,7 @@ def read_token(self):
278276

279277
def sourcehook(self, newfile):
280278
"Hook called on a filename to be sourced."
279+
import os.path
281280
if newfile[0] == '"':
282281
newfile = newfile[1:-1]
283282
# This implements cpp-like semantics for relative-path inclusion.
@@ -318,13 +317,17 @@ def join(split_command):
318317
return ' '.join(quote(arg) for arg in split_command)
319318

320319

321-
_find_unsafe = re.compile(r'[^\w@%+=:,./-]', re.ASCII).search
322-
323320
def quote(s):
324321
"""Return a shell-escaped version of the string *s*."""
325322
if not s:
326323
return "''"
327-
if _find_unsafe(s) is None:
324+
325+
# Use bytes.translate() for performance
326+
safe_chars = (b'%+,-./0123456789:=@'
327+
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ_'
328+
b'abcdefghijklmnopqrstuvwxyz')
329+
# No quoting is needed if `s` is an ASCII string consisting only of `safe_chars`
330+
if s.isascii() and not s.encode().translate(None, delete=safe_chars):
328331
return s
329332

330333
# use single quotes, and put single quotes into double quotes

Lib/test/datetimetester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ def test_fromisoformat_fails(self):
20872087
'10000-W25-1', # Invalid year
20882088
'2020-W25-0', # Invalid day-of-week
20892089
'2020-W25-8', # Invalid day-of-week
2090+
'٢025-03-09' # Unicode characters
20902091
'2009\ud80002\ud80028', # Separators are surrogate codepoints
20912092
]
20922093

@@ -3542,7 +3543,7 @@ def test_fromisoformat_fails_datetime(self):
35423543
'2009-04-19T03:15:4500:00', # Bad time zone separator
35433544
'2009-04-19T03:15:45.123456+24:30', # Invalid time zone offset
35443545
'2009-04-19T03:15:45.123456-24:30', # Invalid negative offset
3545-
'2009-04-10ᛇᛇᛇᛇᛇ12:15', # Too many unicode separators
3546+
'2009-04-10ᛇᛇᛇᛇᛇ12:15', # Unicode chars
35463547
'2009-04\ud80010T12:15', # Surrogate char in date
35473548
'2009-04-10T12\ud80015', # Surrogate char in time
35483549
'2009-04-19T1', # Incomplete hours

Lib/test/test_capi/test_file.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,28 @@ def test_py_fopen(self):
294294
# CRASHES py_fopen(NULL, 'rb')
295295
# CRASHES py_fopen(__file__, NULL)
296296

297-
# TODO: Test Py_UniversalNewlineFgets()
297+
def test_py_universalnewlinefgets(self):
298+
py_universalnewlinefgets = _testcapi.py_universalnewlinefgets
299+
filename = os_helper.TESTFN
300+
self.addCleanup(os_helper.unlink, filename)
301+
302+
with open(filename, "wb") as fp:
303+
fp.write(b"line1\nline2")
304+
305+
line = py_universalnewlinefgets(filename, 1000)
306+
self.assertEqual(line, b"line1\n")
307+
308+
with open(filename, "wb") as fp:
309+
fp.write(b"line2\r\nline3")
310+
311+
line = py_universalnewlinefgets(filename, 1000)
312+
self.assertEqual(line, b"line2\n")
313+
314+
with open(filename, "wb") as fp:
315+
fp.write(b"line3\rline4")
316+
317+
line = py_universalnewlinefgets(filename, 1000)
318+
self.assertEqual(line, b"line3\n")
298319

299320
# PyFile_SetOpenCodeHook() and PyFile_OpenCode() are tested by
300321
# test_embed.test_open_code_hook()

Lib/test/test_ioctl.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
fcntl = import_module('fcntl')
1111
termios = import_module('termios')
1212

13-
try:
14-
import pty
15-
except ImportError:
16-
pty = None
17-
1813
class IoctlTestsTty(unittest.TestCase):
1914
@classmethod
2015
def setUpClass(cls):
@@ -137,10 +132,10 @@ def test_ioctl_mutate_2048(self):
137132
self.assertRaises(ValueError, self._check_ioctl_not_mutate_len, 2048)
138133

139134

140-
@unittest.skipIf(pty is None, 'pty module required')
135+
@unittest.skipUnless(hasattr(os, 'openpty'), "need os.openpty()")
141136
class IoctlTestsPty(unittest.TestCase):
142137
def setUp(self):
143-
self.master_fd, self.slave_fd = pty.openpty()
138+
self.master_fd, self.slave_fd = os.openpty()
144139
self.addCleanup(os.close, self.slave_fd)
145140
self.addCleanup(os.close, self.master_fd)
146141

0 commit comments

Comments
 (0)