Skip to content

Admit that **kwargs mapping subtypes may have no direct type parameters - #18850

Merged
hauntsaninja merged 1 commit into
python:masterfrom
sterliakov:bugfix/gh-13675-mapping-unpack
Mar 29, 2025
Merged

Admit that **kwargs mapping subtypes may have no direct type parameters#18850
hauntsaninja merged 1 commit into
python:masterfrom
sterliakov:bugfix/gh-13675-mapping-unpack

Conversation

@sterliakov

Copy link
Copy Markdown
Collaborator

Fixes#13675. I don't know why this check was ever needed (since #11151), but it doesn't seem correct.

@hauntsaninjahauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Not sure what this was about (although maybe primer will tell us)

@github-actions

Copy link
Copy Markdown
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]

@sterliakov

sterliakov commented Mar 29, 2025

Copy link
Copy Markdown
CollaboratorAuthor

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 Required:

https://github.com/mit-ll-responsible-ai/hydra-zen/blob/0ae045b3ae68b3227a3462815014099920e3ed53/src/hydra_zen/typing/_implementations.py#L432

(trivial to fix and worth fixing anyway, last wrapper dict should just go away, and version condition can define StrictDataclassOptions immediately; mypy struggles to track that StrictDataclassOptions is still a TypedDict, type ignore is for Required[] can be only used in a TypedDict definition error)

The error on our end is cryptic as always with ** unpacking, but it in't a problem to solve in this PR.

Min-ish repro:

importsysfromdataclassesimportField, make_dataclassfromtypingimportAny, ClassVar, Protocol, Required, TypedDictclassDataClass_(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
class_BaseOptions(TypedDict, total=False):
cls_name: strnamespace: dict[str, Any] |Nonebases: tuple[type[DataClass_], ...]
init: boolrepr: booleq: boolorder: boolunsafe_hash: boolfrozen: boolclassPy310Options(_BaseOptions):
match_args: boolkw_only: boolslots: boolifsys.version_info< (3, 10):
BaseOptions=_BaseOptionselse:
BaseOptions=Py310OptionsclassStrictOptions(BaseOptions):
cls_name: Required[str] # type: ignoredefchk(o: StrictOptions) ->None:
make_dataclass(fields=[], **o)

@sterliakov
sterliakov marked this pull request as ready for review March 29, 2025 02:56
@hauntsaninja
hauntsaninja merged commit 6badb4a into python:masterMar 29, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test testPassingMappingSubclassForKeywordVarArg is wrong

2 participants

@sterliakov@hauntsaninja