Skip to content

bug: PEP 810 __lazy_modules__  should not be detected as a public module attribute #506

Closed

Description

@edgarrmondragon

Description of the bug

Adding or removing imports can lead to changes to the contents of __lazy_modules__, which are currently detected by griffe check as a public API change:

package.module:5: __lazy_modules__: Attribute value was changed: {'itertools', 'warnings'} -> {'importlib', 'itertools', 'warnings'}

To Reproduce

__lazy_modules__ = {"iterools", "warnings"}

import itertools
import warnings

Full traceback

No traceback, but here's an example of the diagnostic again

package.module:5: __lazy_modules__: Attribute value was changed: {'itertools', 'warnings'} -> {'importlib', 'itertools', 'warnings'}

Expected behavior

Changes to __lazy_modules__ behave like changes to imports and are not considered public API.

Environment information

griffe --debug-info  # | xclip -selection clipboard
  • System: macOS-15.8-arm64-arm-64bit-Mach-O
  • Python: cpython 3.15.0 (/Users/me/.cache/uv/archive-v0/3KfL2bp7y7KFtIkA/bin/python)
  • Environment variables:
  • Installed packages:
    • griffelib v2.4.0
    • prune-source v0.0.0
    • griffecli v2.4.0
    • griffe v2.4.0

Additional context

Activity

  1. added
    unconfirmed
    on Oct 20, 2026
  2. pawamoy commented on Oct 21, 2026

    @pawamoy
    Member

    Thanks for the report @edgarrmondragon. This one bothers me 😄 We generally consider special/dunder attributes public, for example __init__ is public because even though you (generally) don't call it directly, it's used when you instantiate a class, or __eq__ is public because it's used when you compare objects, etc.

    I see two options for us here:

    • start special casing special/dunder attributes, for example to consider __lazy_modules__ non-public
    • remove the Attribute value was changed check. I don't think it ever triggered a true-positive in my own projects. If we think about it, it doesn't make much sense: if a user of your code is expecting a variable of yours to be stable, they can use the value directly. If not, then the value is expected to be able to change.

    WDYT?

  3. added
    bug
    and removed
    unconfirmed
    on Oct 21, 2026
  4. pawamoy commented on Oct 21, 2026

    @pawamoy
    Member
  5. edgarrmondragon commented on Oct 21, 2026

    @edgarrmondragon
    Author
    • remove the Attribute value was changed check. I don't think it ever triggered a true-positive in my own projects.

    That's been my exact experience. I've even seen false positives where the actual value didn't change, just how it's computed 🙃

    I'll check the fosstodon conversation.

  6. pawamoy commented on Oct 21, 2026

    @pawamoy
    Member

    Right, it actually doesn't compare the value but the expression that builds it. One more reason to drop it.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions