Skip to content

4.0: tighten the provider surface #566

Closed

Description

@lesnik512

This was generated by AI during a pre-4.0 audit of main at 9cd88e7.

Observation

  • The docs call the provider set closed, yet internal methods are public: AbstractProvider.mark_registered/get_dependencies/redirect_target/iter_validation_issues (providers/abstract.py:43-93), Factory.wiring_plan/can_call_positionally/resolution_step, Alias.find_source, CacheSettings.coerce. No integration calls them; once public in 4.0 they cannot change in a minor.
  • Factory(cache=) accepts three spellings of "off": None, False, absent.
  • AbstractProvider is an abc.ABC with no abstract methods (abstract.py:16). Besides misleading, it makes every isinstance a Python-level __instancecheck__ (98 ns vs 23 ns), hit per injected parameter in Container.resolve_dependency (container.py:156): Marker.resolve 260 -> 183 ns measured on 3.14.
  • modern_di/__init__.py lists "providers" in __all__ without importing it; it works only because container.py imports modern_di.providers.abstract.

Proposal

  • Underscore-prefix the internal methods (keep the public provider API: constructors, bound_type, scope, cast helpers, whatever the docs show).
  • Narrow cache= to bool | CacheSettings.
  • Drop abc.ABC from AbstractProvider.
  • from modern_di import exceptions, integrations, providers.

Acceptance

Tests updated; Factory(cache=None) raises a clear error (or TypeError); migration guide entries; integrations still pass (modern-di-pytest imports AbstractProvider only as a type).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions