Skip to content

Error messages, docstrings, CI and test cleanups found in the third pre-4.0 audit #618

Closed

Description

@lesnik512

This was generated by AI during a third pre-4.0 audit of main at f6e343d.

Non-breaking improvements found in the same audit. None block 4.0.0.

Error messages

  1. Subclassing a provider fails at first resolve with a bare TypeError: no compiled resolver for provider type MyF, and validate() says nothing. Reject at definition time (__init_subclass__) or raise a ModernDIError. tests/test_container.py:224 subclasses Factory.
  2. DuplicateProviderTypeError does not name the two clashing providers, though ProvidersRegistry._add has both; add them with their definition sites. Its second hint ("pass dependencies via kwargs") does not fix a duplicate.
  3. FinalizerError prints [ValueError('boom'), ...] without saying whose finalizer failed. add_note each inner error with the instance type, and use the one-line summary style of ValidationFailedError.

Readability

  1. No docstrings on Factory, Alias, Group, AbstractProvider, CacheSettings, Group.get_providers, get_named_providers; IDE hover shows nothing.
  2. resolver_compiler.py: [*edges][arg_lines[exc.__traceback__.tb_lineno]] needs re-reading; rename arg_lines to arg_index_by_line and spell out f, a, cp. wiring.find_dep_provider and Edge.dep keep the "dep" abbreviation feat!: make exception attributes consistent and ValidationFailedError an ExceptionGroup (#604) #607 removed from the exceptions.

CI and tooling

  1. Action versions: actions/cache@v4 (Node 20 deprecation warning in the benchmarks job), setup-uv v8.2.0, actions/checkout v6. Add dependabot for GitHub Actions.
  2. Benchmarks: the C-series never runs in CI; a --benchmark-disable smoke run (33 tests, about 1 s) in scheduled.yml would catch breakage. The G-series baseline cache key ignores the Python version. Nothing alerts on pushes to main (comment-on-alert: false).
  3. Run the Python code blocks in docs/ and README (190 blocks): ast.parse all, execute those importing only modern-di.
  4. --cov-report xml writes a file nothing uploads. fix = true with unsafe-fixes = true makes a bare ruff check apply unsafe fixes. benchmarks/comparative is neither linted nor type-checked.

Tests

  1. test_container.py:755 assert gc.collect() == 0 depends on global state and adds nothing. test_types_parser.py:252 asserts only provider is not None. ty flags tests/test_types_parser.py:402 on 3.12+.
  2. test_container.py (1200 lines) and test_context_provider.py (1287 lines) mix topics; move export checks to test_packaging.py and context-leak tests next to the container tests.
  3. Consider a scheduled mutmut run over cache.py, container.py, resolver_compiler.py.

Activity

  1. lesnik512 commented on Oct 9, 2026

    @lesnik512
    MemberAuthor

    This was generated by AI.

    Triaged against main at 8892421.

    Doing:

    • 1: reject provider subclasses at class definition. Since refactor: dispatch the dependency graph by provider type, make the provider step a free function (#617) #629 the graph dispatches by exact type, so a Factory subclass gets no validation at all and then fails at first resolve with a bare TypeError.
    • 2: DuplicateProviderTypeError names both providers and drops the kwargs hint.
    • 3: each inner FinalizerError exception gets a note naming the instance type.
    • 4: docstrings on Factory, Alias, Group, AbstractProvider, CacheSettings, Group.get_providers and Group.get_named_providers.
    • 6: only actions/cache v4 to v6 in benchmarks.yml. Dependabot and the checkout / setup-uv versions follow the shared workflow template, which no modern-python repo diverges from.
    • 10: only the gc.collect() == 0 assertion. It counts garbage from the whole process, so it will collect once first.

    Dropped: 5, 7, 8, 9, 11, 12, and the rest of 10.

  2. lesnik512 commented on Oct 9, 2026

    @lesnik512
    MemberAuthor

    This was generated by AI.

    Correction to item 10: test_closed_children_are_freed_without_the_cycle_collector already calls gc.collect() and disables the collector before building the children, so gc.collect() == 0 counts only this test's garbage. No change needed; item 10 is dropped in full.

  3. lesnik512 commented on Oct 10, 2026

    @lesnik512
    MemberAuthor

    This was generated by AI.

    Done: items 1 to 4 in #631, item 6 in #630. #632 fixed the ruff 0.17 lint failure on the way.

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 request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions