Skip to content

Commit 1300d2c

Browse files
committed
fix: Don't deepcopy the local config
This was done in commit 3cbe472 to avoid a type warning that the second and next arguments to ChainMap are not mutable. Related Mypy issue: python/typeshed#8430. When we use `!relative` in MkDocs configuration, the config then contains a MkDocs path placeholder instance, which itself contains a reference to the MkDocs config, and all its plugins, including mkdocstrings, and all its objects, etc. Upon deepcopying this huge object tree, deepcopy fails on mkdocstrings private attribute `_inv_futures`, which contains `Future` and therefore `thread.RLock` objects, which are not serializable. This failed with a `TypeError: cannot pickle '_thread.RLock` objects`. So in this commit we stop deep-copying everything just to avoid a Mypy warning, and instead we add a type-ignore comment. If Mypy fixes this someday, we'll simply get a new warning that the comment is unused.
1 parent 7aad2dd commit 1300d2c

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/mkdocstrings_handlers/python/handler.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import copy
65
import glob
76
import os
87
import posixpath
@@ -260,9 +259,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
260259
if config.get("fallback", False) and unknown_module:
261260
raise CollectionError("Not loading additional modules during fallback")
262261

263-
# See: https://github.com/python/typeshed/issues/8430
264-
mutable_config = dict(copy.deepcopy(config))
265-
final_config = ChainMap(mutable_config, self.default_config)
262+
final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
266263
parser_name = final_config["docstring_style"]
267264
parser_options = final_config["docstring_options"]
268265
parser = parser_name and Parser(parser_name)
@@ -308,9 +305,7 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
308305
return doc_object
309306

310307
def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa: D102 (ignore missing docstring)
311-
# See https://github.com/python/typeshed/issues/8430
312-
mutabled_config = dict(copy.deepcopy(config))
313-
final_config = ChainMap(mutabled_config, self.default_config)
308+
final_config = ChainMap(config, self.default_config) # type: ignore[arg-type]
314309

315310
template_name = rendering.do_get_template(data)
316311
template = self.env.get_template(template_name)

0 commit comments

Comments
 (0)