Skip to content

[pull] main from python:main - #1537

Merged
pull[bot] merged 6 commits into
tj-python:mainfrom
python:main
Sep 29, 2026
Merged

pull[bot] merged 6 commits into
tj-python:mainfrom
python:main

Conversation

@pull

@pull pull Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

stratakis and others added 6 commits September 29, 2026 11:12
Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
…157768)

Resolve lazy imports before using them as a mock spec

unittest.mock.patch() reads the attribute it replaces out of
target.__dict__, which for an unresolved lazy import holds a
types.LazyImportType placeholder. spec=True, spec_set=True and
autospec=True then specced the placeholder, so patching a function
produced a NonCallableMagicMock.

Reimplementation of #153977:

- Resolve in _patch.__enter__(), and only when the spec is taken from
  the original, rather than unconditionally in get_original().
  Resolving on every patch() breaks patch("mod.dep", new=...) for a
  lazy import of a module that is not installed.
- Test spec and spec_set as well as autospec, as asked for in review.
- Build the lazy binding in the test instead of importing json lazily
  at module level: "lazy from" binds eagerly when the module is already
  imported, so that test passed without the fix too.
* Add _PyBytes_GET_CACHED_HASH() static inline function.
* _PyBytes_IsMutable() makes sure that the hash value is not cached
  yet.
* bytearray_reinit_from_bytes() checks that the bytes object is
  mutable.

Co-authored-by: Cody Maloney <cmaloney@theoreticalchaos.com>
…#158344)

Do no read output_start pointer after PyBytesWriter_Finish() since
the pointer became a dangling pointer.

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@pull pull Bot locked and limited conversation to collaborators Sep 29, 2026
@pull pull Bot added the ⤵️ pull label Sep 29, 2026
@pull
pull Bot merged commit aa287d7 into tj-python:main Sep 29, 2026
5 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants