Skip to content

Commit 147368a

Browse files
committed
Added (and fixed) Python 3.10 support
1 parent fe49c40 commit 147368a

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

.github/workflows/codeqa-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
fail-fast: false
3232
matrix:
3333
os: [ubuntu-latest]
34-
python-version: [3.6, 3.7, 3.8, 3.9]
34+
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0-alpha.5]
3535
runs-on: ${{ matrix.os }}
3636
steps:
3737
- uses: actions/checkout@v2

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ classifiers =
2222
Programming Language :: Python :: 3.7
2323
Programming Language :: Python :: 3.8
2424
Programming Language :: Python :: 3.9
25+
Programming Language :: Python :: 3.10
2526

2627
[options]
2728
py_modules = sphinx_autodoc_typehints

sphinx_autodoc_typehints.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def get_annotation_args(annotation, module: str, class_name: str) -> Tuple:
8787
def format_annotation(annotation,
8888
fully_qualified: bool = False,
8989
simplify_optional_unions: bool = True) -> str:
90+
print(f'formatting annotation: {annotation!r} ({type(annotation)})')
9091
# Special cases
9192
if annotation is None or annotation is type(None): # noqa: E721
9293
return ':py:obj:`None`'
@@ -105,7 +106,7 @@ def format_annotation(annotation,
105106
class_name = get_annotation_class_name(annotation, module)
106107
args = get_annotation_args(annotation, module, class_name)
107108
except ValueError:
108-
return str(annotation)
109+
return str(annotation).strip("'")
109110

110111
# Redirect all typing_extensions types to the stdlib typing module
111112
if module == 'typing_extensions':
@@ -165,6 +166,8 @@ def process_signature(app, what: str, name: str, obj, options, signature, return
165166
param.replace(annotation=inspect.Parameter.empty)
166167
for param in signature.parameters.values()
167168
]
169+
if name == 'dummy_module.function_with_unresolvable_annotation':
170+
print(f' parameters: {parameters}')
168171

169172
# The generated dataclass __init__() and class are weird and need extra checks
170173
# This helper function operates on the generated class and methods
@@ -186,6 +189,8 @@ def _is_dataclass(name: str, what: str, qualname: str) -> bool:
186189
return
187190

188191
if parameters:
192+
if name == 'dummy_module.function_with_unresolvable_annotation':
193+
print(' formatting parameters')
189194
if inspect.isclass(original_obj) or (what == 'method' and name.endswith('.__init__')):
190195
del parameters[0]
191196
elif what == 'method':
@@ -209,6 +214,8 @@ def _is_dataclass(name: str, what: str, qualname: str) -> bool:
209214
parameters=parameters,
210215
return_annotation=inspect.Signature.empty)
211216

217+
if name == 'dummy_module.function_with_unresolvable_annotation':
218+
print(' stringifying signature')
212219
return stringify_signature(signature).replace('\\', '\\\\'), None
213220

214221

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
minversion = 3.3.0
3-
envlist = py36, py37, py38, py39, flake8
3+
envlist = py36, py37, py38, py39, py310, flake8
44
skip_missing_interpreters = true
55
isolated_build = true
66

0 commit comments

Comments
 (0)