Skip to content

Use Any for field type in make_dataclass - #11657

Merged
AlexWaygood merged 4 commits into
python:mainfrom
alexei:fix-11653-make_dataclass_type_hints
Mar 25, 2024
Merged

AlexWaygood merged 4 commits into
python:mainfrom
alexei:fix-11653-make_dataclass_type_hints

Conversation

@alexei

@alexei alexei commented Mar 25, 2024

Copy link
Copy Markdown
Contributor

Fixes #11653

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Can this be object instead?

@JelleZijlstra

Copy link
Copy Markdown
Member

I think Any is more appropriate because we don't really want to accept all objects. For example, ideally we'd reject make_dataclass("T", [("x", 1)]).

@AlexWaygood

Copy link
Copy Markdown
Member

Yeah, I agree with Jelle. It can't actually be any object, so object isn't really accurate. The type just can't be expressed without a TypeForm-esque thing.

@github-actions

This comment has been minimized.

Comment thread test_cases/stdlib/check_dataclasses.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood changed the title fix: use Any for field type in make_dataclass Use Any for field type in make_dataclass Mar 25, 2024
@AlexWaygood
AlexWaygood merged commit 4df0725 into python:main Mar 25, 2024
@AlexWaygood

Copy link
Copy Markdown
Member

Thanks @alexei!

@alexei
alexei deleted the fix-11653-make_dataclass_type_hints branch March 26, 2024 11:20
@alexei

alexei commented Mar 26, 2024

Copy link
Copy Markdown
Contributor Author

Thanks guys!

Sign up for free to 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.

dataclasses.make_dataclass should accept Any, not type

4 participants