From 477b9e447ef9717c6edcb14bd4c53f9cacc555b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 4 Feb 2025 02:29:19 +0100 Subject: [PATCH 1/2] fix: Let dataclass implement `__init__` method, set extra fields in `get_options` With our own `__init__` implementation, unpassed fields would never be set on the instance, triggering attribute errors. Let dataclass do its job, add set extra fields from outside of the class. --- src/mkdocstrings_handlers/python/config.py | 9 --------- src/mkdocstrings_handlers/python/handler.py | 9 +++++++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/mkdocstrings_handlers/python/config.py b/src/mkdocstrings_handlers/python/config.py index 5e444d27..fa8aa009 100644 --- a/src/mkdocstrings_handlers/python/config.py +++ b/src/mkdocstrings_handlers/python/config.py @@ -843,15 +843,6 @@ def _extract_extra(cls, data: dict[str, Any]) -> tuple[dict[str, Any], dict[str, copy = data.copy() return {name: copy.pop(name) for name in data if name not in field_names}, copy - # YORE: Bump 2: Remove block. - def __init__(self, **kwargs: Any) -> None: - """Initialize the instance.""" - extra_fields = self._extract_extra(kwargs) - for name, value in kwargs.items(): - object.__setattr__(self, name, value) - if extra_fields: - object.__setattr__(self, "_extra", extra_fields) - @classmethod def coerce(cls, **data: Any) -> MutableMapping[str, Any]: """Coerce data.""" diff --git a/src/mkdocstrings_handlers/python/handler.py b/src/mkdocstrings_handlers/python/handler.py index 7ef6b358..978488b3 100644 --- a/src/mkdocstrings_handlers/python/handler.py +++ b/src/mkdocstrings_handlers/python/handler.py @@ -186,12 +186,17 @@ def get_options(self, local_options: Mapping[str, Any]) -> HandlerOptions: extra = {**self.global_options.get("extra", {}), **local_options.get("extra", {})} options = {**self.global_options, **local_options, "extra": extra} - # YORE: Bump 2: Replace `, **unknown_extra` with `` within line. try: - return PythonOptions.from_data(**options, **unknown_extra) + # YORE: Bump 2: Replace `opts =` with `return` within line. + opts = PythonOptions.from_data(**options) except Exception as error: raise PluginError(f"Invalid options: {error}") from error + # YORE: Bump 2: Remove block. + for key, value in unknown_extra.items(): + object.__setattr__(opts, key, value) + return opts + def collect(self, identifier: str, options: PythonOptions) -> CollectorItem: # noqa: D102 module_name = identifier.split(".", 1)[0] unknown_module = module_name not in self._modules_collection From e74ecbf15a495183c1f78eb2257a262721fb502d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Tue, 4 Feb 2025 02:31:25 +0100 Subject: [PATCH 2/2] chore: Prepare release 1.14.3 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d31fb5ab..f3a72ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [1.14.3](https://github.com/mkdocstrings/python/releases/tag/1.14.3) - 2025-02-04 + +[Compare with 1.14.2](https://github.com/mkdocstrings/python/compare/1.14.2...1.14.3) + +### Bug Fixes + +- Let dataclass implement `__init__` method, set extra fields in `get_options` ([477b9e4](https://github.com/mkdocstrings/python/commit/477b9e447ef9717c6edcb14bd4c53f9cacc555b8) by Timothée Mazzucotelli). + ## [1.14.2](https://github.com/mkdocstrings/python/releases/tag/1.14.2) - 2025-02-03 [Compare with 1.14.1](https://github.com/mkdocstrings/python/compare/1.14.1...1.14.2)