Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autodoc_type_aliases configuration #459

Merged
merged 12 commits into from
Jun 19, 2024

Conversation

tikuma-lsuhsc
Copy link
Contributor

This PR addresses Issues #284.

Currently, autodoc-typehints does not honor the autodoc_type_aliases configuration of sphinx.ext.autodoc. For example,

from numpy.typing import ArrayLike

def func(x: ArrayLike):...

renders

**func(x: _SupportsArray[dtype[Any]] |
_NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float |
complex | str | bytes | _NestedSequence[bool | int | float | complex |
str | bytes])

even if autodoc_type_aliases = {'ArrayLike': 'ArrayLike'} line in conf.py.

I modified autodoc_typehints to pass app.config.autodoc_type_aliases to sphinx_signature() calls to match sphinx.ext.autodoc and print the alias instead of the annotation as discovered.

test_integration_autodoc_type_aliases.py is a simple pytest script to check the conservation of ArrayLike annotation in a function argument.

gaborbernat
gaborbernat previously approved these changes Jun 17, 2024
@gaborbernat gaborbernat enabled auto-merge (squash) June 17, 2024 02:06
@tikuma-lsuhsc
Copy link
Contributor Author

@gaborbernat - Could you help me sort out the tox env type check errors?

I'm getting

tests/test_integration_autodoc_type_aliases.py:22: error: "T" has no attribute "EXPECTED"  [attr-defined]
tests/test_integration_autodoc_type_aliases.py:23: error: "T" has no attribute "OPTIONS"  [attr-defined]
tests/test_integration_autodoc_type_aliases.py:31: error: "T" has no attribute "WARNING"  [attr-defined]
tests/test_integration_autodoc_type_aliases.py:56: error: Missing return statement  [empty-body]

I got the last one, but not clear about the others. I created the test file by copying then stripping away existing tests of the test_integration.py. Thanks

@gaborbernat
Copy link
Member

Nothing jumps out for me from the top of my head. 🤔

@tikuma-lsuhsc
Copy link
Contributor Author

OK. I'll look into it when I get home tonight.

auto-merge was automatically disabled June 18, 2024 00:27

Head branch was pushed to by a user without write access

@tikuma-lsuhsc
Copy link
Contributor Author

Resolved the issue (I think). The test file test_integration.py was excluded from the mypy type check via pyproject.toml. If you try to merge again, it should work now. Thanks.

Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat gaborbernat enabled auto-merge (squash) June 19, 2024 14:17
@gaborbernat gaborbernat merged commit fb240ea into tox-dev:main Jun 19, 2024
9 checks passed
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.

2 participants