Skip to content

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

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

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions