so that
$ python -m json.tool foo.json foo.json
doesn't result in an empty foo.json.
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 815dad42d5)
Co-authored-by: Chris Wesseling <chris.wesseling@protonmail.com>
In order to fix a bug in the 3.9 branch in GH-29394, more tests were added to
``test_functools.py`` to ensure that ``singledispatchmethod`` still correctly
wrapped a target method, even if the target method had already been wrapped by
multiple other decorators. This PR brings the new tests into the 3.11 and 3.10
branches as well.
(cherry picked from commit 32f55d1a5d)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* Don't stackoveflow on debug builds
* Also catch the pickletester case
(cherry picked from commit d56375a0dd)
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Run test_shelve with all underlying dbm implementations and pickle protocols.
Also make test_shelve discoverable.
(cherry picked from commit b781cc3bfc)
the current test depended on integer sets being iterated on in a certain
fixed order. That order is different on PyPy (insertion based) and could
change in CPython in the future in theory. Make the test robust against
a different iteration order by sorting.
(cherry picked from commit 7401694807)
Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
The doctest module raised an error if a docstring contained an example that
attempted to access a classmethod property. (Stacking '@classmethod' on top of
`@property` has been supported since Python 3.9; see
https://docs.python.org/3/howto/descriptor.htmlGH-class-methods.)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit b1302abcc8)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Use types.GenericAlias in inspect.formatannotation to correctly add
type arguments of builtin types to the string representation of
Signatures.
Co-authored-by: Martin Rückl <martin.rueckl@codecentric.de>
(cherry picked from commit d02ffd1b5c)
Co-authored-by: Martin Rueckl <enigma@nbubu.de>
* Use Py_EnterRecursiveCall() in issubclass()
Reviewed-by: Gregory P. Smith <greg@krypto.org> [Google]
(cherry picked from commit 423fa1c181)
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Raise RLIMIT_NOFILE in test.libregrtest.
On macOS the default is often too low for our testsuite to succeed.
Co-authored by reviewer: Victor Stinner
(cherry picked from commit 843b890334)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
An object implementing the os.PathLike protocol can represent a file
system path as a str or bytes object.
Therefore, _infer_return_type function should infer os.PathLike[str]
object as str type and os.PathLike[bytes] object as bytes type.
(cherry picked from commit 6270d3eeaf)
Co-authored-by: Kyungmin Lee <rekyungmin@gmail.com>
In Python 3.8 and 3.9, stacking `@functools.singledispatchmethod` on top of
`@classmethod` or `@staticmethod` caused an exception to be raised if the
method was registered using type-annotations rather than
`@method.register(int)`. This was not caught by unit tests, however, as the
tests only tested the `@method.register(int)` way of registering additional
implementations. The bug is no longer present in Python 3.10+, but
`test_functools.py` is still lacking regression tests for these cases. This
commit adds these test cases.
(cherry picked from commit ad6d162e51)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
There are two errors that this commit fixes:
* The parser was not correctly computing the offset and the string
source for E_LINECONT errors due to the incorrect usage of strtok().
* The parser was not correctly unwinding the call stack when a tokenizer
exception happened in rules involving optionals ('?', [...]) as we
always make them return valid results by using the comma operator. We
need to check first if we don't have an error before continuing..
(cherry picked from commit a106343f63)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* Generate test classes at import time. It allows to filter them when
run with unittest. E.g: "./python -m unittest test.test_dbm.TestCase_gnu -v".
* Create a database class in a new directory which will be removed after
test. It guarantees that all created files and directories be removed
and will not conflict with other dbm tests.
* Restore dbm._defaultmod after tests. Previously it was set to the last
dbm module (dbm.dumb) which affected other tests.
* Enable the whichdb test for dbm.dumb.
* Move test_keys to the correct test class. It does not test whichdb().
* Remove some outdated code and comments..
(cherry picked from commit 975b94b9de)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
They support now splitting escape sequences between input chunks.
Add the third parameter "final" in codecs.raw_unicode_escape_decode().
It is True by default to match the former behavior.
(cherry picked from commit 39aa98346d)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
They support now splitting escape sequences between input chunks.
Add the third parameter "final" in codecs.unicode_escape_decode().
It is True by default to match the former behavior.
(cherry picked from commit c96d1546b1)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
test_embed.StdPrinterTests now always use the file descriptor 1 for
stdout, rather than using sys.__stdout__.fileno().
PyFile_NewStdPrinter() does crash if the argument is not 1 or 2.
Fix also a few pyflakes warnings: remove unused import and variables.
(cherry picked from commit 678433f25e)
Co-authored-by: Victor Stinner <vstinner@python.org>
Fix typos in the Lib directory as identified by codespell.
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>.
(cherry picked from commit 745c9d9dfc)
Co-authored-by: Christian Clauss <cclauss@me.com>
Fix test_name_error_suggestions_do_not_trigger_for_too_many_locals()
of test_exceptions if a directory name contains "a1" (like
"Python-3.11.0a1"): use a stricter regular expression.
(cherry picked from commit 4e605666b0)
Co-authored-by: Victor Stinner <vstinner@python.org>
Make enter_context(foo()) / enter_async_context(foo()) equivalent to
`[async] with foo()` regarding __context__ when an exception is raised.
Previously exceptions would be caught and re-raised with the wrong
context when explicitly overriding __context__ with None..
(cherry picked from commit e6d1aa1ac6)
Co-authored-by: John Belmonte <john@neggie.net>
Automerge-Triggered-By: GH:njsmith
Add a PID to names of POSIX shared memory objects to allow
running multiprocessing tests (test_multiprocessing_fork,
test_multiprocessing_spawn, etc) in parallel.
(cherry picked from commit eb4495e8e2)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Work correctly if an additional fresh module imports other
additional fresh module which imports a blocked module.
* Raises ImportError if the specified module cannot be imported
while all additional fresh modules are successfully imported.
* Support blocking packages.
* Always restore the import state of fresh and blocked modules
and their submodules.
* Fix test_decimal and test_xml_etree which depended on an undesired
side effect of import_fresh_module().
(cherry picked from commit ec4d917a6a)
* during tarfile parsing, a zlib error indicates invalid data
* tarfile.open now raises a descriptive exception from the zlib error
* this makes it clear to the user that they may be trying to open a
corrupted tar file
(cherry picked from commit b6fe857250)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>