• 
      

    Modernize autodoc_utils.

    Review Request #14479 — Created June 27, 2025 and submitted

    Information

    beanbag-docutils
    master

    Reviewers

    This change modernizes out autodoc_utils Sphinx extension in preparation
    for adding new features to better deal with TypedDicts.

    Ran unit tests.

    Summary ID
    Modernize autodoc_utils.
    This change modernizes out autodoc_utils Sphinx extension in preparation for adding new features to better deal with TypedDicts. Testing Done: Ran unit tests.
    5094ab32c155384c3486f4da79d6833f94403c94
    Description From Last Updated

    The trick to avoiding the warnings that you're having to ignore here is to do: try: ... except ImportError: if …

    chipx86chipx86

    Probably should capitalize "Returns". Also, "Returns-like", since it's more than "Returns".

    chipx86chipx86

    What's this for? We should document every # type: ignore so it's clear.

    chipx86chipx86

    What's this for?

    chipx86chipx86

    No need for these parens now.

    chipx86chipx86

    Why this? Let's document these. Here and below.

    chipx86chipx86

    I don't think the r is needed.

    chipx86chipx86

    Why this?

    chipx86chipx86

    undefined name 'Sequence' Column: 29 Error code: F821

    reviewbotreviewbot

    undefined name 'Sequence' Column: 28 Error code: F821

    reviewbotreviewbot

    undefined name 'Sequence' Column: 34 Error code: F821

    reviewbotreviewbot

    Space after "type:". I guess either works? But that's how it's documented and commonly used.

    chipx86chipx86
    david
    chipx86
    1. 
        
    2. beanbag_docutils/sphinx/ext/autodoc_utils.py (Diff revision 2)
       
       
       
       
       
      Show all issues

      The trick to avoiding the warnings that you're having to ignore here is to do:

      try:
          ...
      except ImportError:
          if TYPE_CHECKING:
              assert False
          else:
              ...
      

      This ensures that the type checker only ever considers the first import and not whatever we have to patch in after. It also avoids the issue of ignoring the true imports and only considering the fallbacks (which shouldn't be the primary reference point for the type).

      The way that's structured is very specific. It'll ensure that the type checker does not consider any code paths involving the fallbacks, either within this try/except or later where they're used. Just doing assert not TYPE_CHECKING or if not TYPE_CHECKING: won't give the same result.

    3. Show all issues

      Probably should capitalize "Returns".

      Also, "Returns-like", since it's more than "Returns".

    4. Show all issues

      What's this for?

      We should document every # type: ignore so it's clear.

      1. Type checker noise: Operator ">=" not supported for types "tuple[Literal[7], Literal[4]]" and "tuple[Literal[5], Literal[1]]"

    5. Show all issues

      What's this for?

      1. Fixed by annotating extra_returns_sections

    6. beanbag_docutils/sphinx/ext/autodoc_utils.py (Diff revision 2)
       
       
       
       
       
       
       
       
       
      Show all issues

      No need for these parens now.

    7. Show all issues

      Why this? Let's document these. Here and below.

    8. Show all issues

      I don't think the r is needed.

    9. Show all issues

      Why this?

    10. 
        
    david
    Review request changed
    Commits:
    Summary ID
    Modernize autodoc_utils.
    This change modernizes out autodoc_utils Sphinx extension in preparation for adding new features to better deal with TypedDicts. Testing Done: Ran unit tests.
    b4971b4916c64e29493527531c24596c2e606bfc
    Modernize autodoc_utils.
    This change modernizes out autodoc_utils Sphinx extension in preparation for adding new features to better deal with TypedDicts. Testing Done: Ran unit tests.
    a0c5155e91e0fc1a39d5223e8018e1cbde8b83f1

    Checks run (1 failed, 1 succeeded)

    flake8 failed.
    JSHint passed.

    flake8

    david
    maubin
    1. Ship It!
    2. 
        
    chipx86
    1. Awesome.

    2. Show all issues

      Space after "type:".

      I guess either works? But that's how it's documented and commonly used.

    3. 
        
    david
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to master (947550c)