Skip to content

Lazy import triggers C assert if reading spec._initializing raises #158402

Closed

Description

@encukou

Bug report

Bug description:

This has been crashing in debug mode since the initial lazy import implementation:

import sys
import types

class Spec:
    @property
    def _initializing(self):
        raise RuntimeError("boom")

module = types.ModuleType("cached_spec")
module.__spec__ = Spec()
module.attr = 1
sys.modules["cached_spec"] = module

# This line fails, but cannot be in a try block:
lazy from cached_spec import attr
python3.15d: /builddir/build/BUILD/python3.15-3.15.0_rc2-build/Python-3.15.0rc2/Python/generated_cases.c.h:7979: _PyEval_EvalFrameDefault: Assertion `!_PyErr_Occurred(tstate)' failed.
Aborted                    (core dumped) python3.15d /tmp/repro.py

CPython versions tested on:

3.15, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    type-bug
    interpreter-core
    on Sep 29, 2026
  2. self-assigned this
    on Sep 29, 2026
  3. added 2 commits that reference this issue on Sep 29, 2026
  4. encukou commented on Oct 1, 2026

    @encukou
    MemberAuthor

    Fixed by #158282

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-coretopic-lazy-importstype-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions