Skip to content

fix: preserve MRO order in Class._bases when __orig_bases__ is present - #909

Open
abhishekrajv7-cmd wants to merge 1 commit into
mitmproxy:mainfrom
abhishekrajv7-cmd:fix/inherited-init-documentation
Open

abhishekrajv7-cmd wants to merge 1 commit into
mitmproxy:mainfrom
abhishekrajv7-cmd:fix/inherited-init-documentation

Conversation

@abhishekrajv7-cmd

Copy link
Copy Markdown

Fixes #903

Cause

Class._bases previously placed isinstance(base, type) entries from __orig_bases__ before self.obj.__mro__. When a class inherits from both a concrete base class and a typing construct (such as class Stuff(Base, Iterable):), __orig_bases__ contains Base, putting Base ahead of Stuff in _bases. As a result, _declarations and _member_objects attributed Stuff.__init__ (and other overridden members) to Base.

Changes

  • Update Class._bases in pdoc/doc.py to place self.obj (mro[0]) first, followed by any type entries from __orig_bases__ not already in mro (e.g. TypedDict bases on Python >= 3.12), followed by mro[1:], deduplicated with dict.fromkeys.
  • Add test_bases_mro_order_with_orig_bases in test/test_doc.py covering overridden __init__, indirect MRO ordering with __orig_bases__, and TypedDict field overrides.
  • Update test/testdata/typed_dict.txt where Bar and Baz now list their own attributes before inherited ones.

Verification

  • ruff check .
  • ruff format --check pdoc/doc.py test/test_doc.py
  • mypy pdoc test
  • pytest --cov=pdoc --cov-report term-missing -m "not slow" (153 passed, 2 skipped on Python 3.13.14; 100% coverage on pdoc/doc.py)

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inheritance may in some cases prevent the documentation for a documented constructor to be generated

1 participant