GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Lazy import triggers C assert if reading `spec._initializing` raises · Issue #158402 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Lazy import triggers C assert if reading spec._initializing raises#158402
Copy link
Assignees
encukou
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@encukou
encukou
opened on Sep 29, 2026
Issue body actions

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

  • gh-158402: Clear error if PyImport_GetModule raises in lazy import #158403

Activity

  1. encukou
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    topic-lazy-imports
    on Sep 29, 2026
  2. encukou
    self-assigned this
    on Sep 29, 2026
  3. encukou
    added 2 commits that reference this issue on Sep 29, 2026

    pythongh-158402: Clear error if PyImport_GetModule raises in lazy import

    91c5086

    pythongh-158402: Clear error if PyImport_GetModule raises in lazy import

    6024279
  4. encukou commented on Oct 1, 2026

    @encukou
    encukou
    on Oct 1, 2026
    MemberAuthor
    More actions

    Fixed by #158282

  5. encukou
    closed this as completedon Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @encukou
    encukou

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.