Skip to content

fix: Fix types #53

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

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ tests = [
"pytest-xdist>=2.4",
]
typing = [
"mypy>=0.910",
"mypy>=0.911",
"types-markdown>=3.3",
"types-toml>=0.10",
]
Expand Down
15 changes: 10 additions & 5 deletions src/mkdocstrings_handlers/python/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from __future__ import annotations

import copy
import glob
import os
import posixpath
import re
import sys
from collections import ChainMap
from contextlib import suppress
from typing import Any, BinaryIO, Iterator, Optional, Tuple
from typing import Any, BinaryIO, Iterator, Mapping, Optional, Tuple

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

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

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

return doc_object

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

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

Expand Down