Admit that **kwargs mapping subtypes may have no direct type parameters#18850
Merged
hauntsaninja merged 1 commit intopython:masterfrom Mar 29, 2025
Merged
Conversation
hauntsaninja
approved these changes
Mar 29, 2025
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_implementations.py:2950: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "str" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:2950: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "tuple[type, ...]" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:2950: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "dict[str, Any] | None" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:2950: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "bool" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:2950: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "str | None" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:3310: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "str" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:3310: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "tuple[type, ...]" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:3310: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "dict[str, Any] | None" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:3310: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "bool" [arg-type]
+ src/hydra_zen/structured_configs/_implementations.py:3310: error: Argument 2 to "make_dataclass" has incompatible type "**StrictDataclassOptions"; expected "str | None" [arg-type]
|
Collaborator
Author
|
Okay, I'm lost in that 1000+ LOC method, looks quite scary, but fortunately it isn't relevant. The actual bug is here, attempt to overwrite a key with itself but (trivial to fix and worth fixing anyway, last wrapper dict should just go away, and version condition can define The error on our end is cryptic as always with Min-ish repro: import sys
from dataclasses import Field, make_dataclass
from typing import Any, ClassVar, Protocol, Required, TypedDict
class DataClass_(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
class _BaseOptions(TypedDict, total=False):
cls_name: str
namespace: dict[str, Any] | None
bases: tuple[type[DataClass_], ...]
init: bool
repr: bool
eq: bool
order: bool
unsafe_hash: bool
frozen: bool
class Py310Options(_BaseOptions):
match_args: bool
kw_only: bool
slots: bool
if sys.version_info < (3, 10):
BaseOptions = _BaseOptions
else:
BaseOptions = Py310Options
class StrictOptions(BaseOptions):
cls_name: Required[str] # type: ignore
def chk(o: StrictOptions) -> None:
make_dataclass(fields=[], **o) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #13675. I don't know why this check was ever needed (since #11151), but it doesn't seem correct.