Skip to content

Commit 73ea570

Browse files
ci: Fix typing
Fixes problems reported by mypy. Related typeshed issue: python/typeshed#8430 PR #53: mkdocstrings/python#53
1 parent 02b1676 commit 73ea570

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ tests = [
9898
"pytest-xdist>=2.4",
9999
]
100100
typing = [
101-
"mypy>=0.910",
101+
"mypy>=0.911",
102102
"types-markdown>=3.3",
103103
"types-toml>=0.10",
104104
]

src/mkdocstrings_handlers/python/handler.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
from __future__ import annotations
44

5+
import copy
56
import glob
67
import os
78
import posixpath
89
import re
910
import sys
1011
from collections import ChainMap
1112
from contextlib import suppress
12-
from typing import Any, BinaryIO, Iterator, Optional, Tuple
13+
from typing import Any, BinaryIO, Iterator, Mapping, Optional, Tuple
1314

1415
from griffe.agents.extensions import load_extensions
1516
from griffe.collections import LinesCollection, ModulesCollection
@@ -189,13 +190,15 @@ def load_inventory(
189190
for item in Inventory.parse_sphinx(in_file, domain_filter=("py",)).values(): # noqa: WPS526
190191
yield item.name, posixpath.join(base_url, item.uri)
191192

192-
def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102,WPS231
193+
def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem: # noqa: D102,WPS231
193194
module_name = identifier.split(".", 1)[0]
194195
unknown_module = module_name not in self._modules_collection
195196
if config.get("fallback", False) and unknown_module:
196197
raise CollectionError("Not loading additional modules during fallback")
197198

198-
final_config = ChainMap(config, self.default_config)
199+
# See: https://github.com/python/typeshed/issues/8430
200+
mutable_config = dict(copy.deepcopy(config))
201+
final_config = ChainMap(mutable_config, self.default_config)
199202
parser_name = final_config["docstring_style"]
200203
parser_options = final_config["docstring_options"]
201204
parser = parser_name and Parser(parser_name)
@@ -232,8 +235,10 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
232235

233236
return doc_object
234237

235-
def render(self, data: CollectorItem, config: dict) -> str: # noqa: D102 (ignore missing docstring)
236-
final_config = ChainMap(config, self.default_config)
238+
def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa: D102 (ignore missing docstring)
239+
# See https://github.com/python/typeshed/issues/8430
240+
mutabled_config = dict(copy.deepcopy(config))
241+
final_config = ChainMap(mutabled_config, self.default_config)
237242

238243
template = self.env.get_template(f"{data.kind.value}.html")
239244

0 commit comments

Comments
 (0)