Skip to content
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

fix(dataclass): unify and clarify overloads for cls None #13190

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Alviner
Copy link

@Alviner Alviner commented Dec 4, 2024

fixes #13189

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Dec 4, 2024

Diff from mypy_primer, showing the effect of this PR on open source code:

pydantic (https://github.com/pydantic/pydantic)
+ pydantic/v1/dataclasses.py:214: error: Incompatible types in assignment (expression has type "type[Any]", variable has type "DataclassProxy")  [assignment]
- pydantic/v1/dataclasses.py:214: error: No overload variant of "dataclass" matches argument types "type[Any]", "bool", "bool", "bool", "bool", "bool", "bool", "bool"  [call-overload]
- pydantic/v1/dataclasses.py:214: note: Possible overload variants:
- pydantic/v1/dataclasses.py:214: note:     def dataclass(None, /) -> Callable[[type[_T]], type[_T]]
- pydantic/v1/dataclasses.py:214: note:     def [_T] dataclass(type[_T], /) -> type[_T]
- pydantic/v1/dataclasses.py:214: note:     def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., match_args: bool = ..., kw_only: bool = ..., slots: bool = ..., weakref_slot: bool = ...) -> Callable[[type[_T]], type[_T]]
+ pydantic/dataclasses.py:256: error: Unused "type: ignore" comment  [unused-ignore]

@Alviner
Copy link
Author

Alviner commented Dec 27, 2024

@AlexWaygood Hi! Could you please take a look at this PR when you have a moment? If you’re not available, could you tag someone who might be able to review it?
I’d really appreciate the help. Thank you in advance!

@@ -55,13 +55,51 @@ def astuple(obj: DataclassInstance) -> tuple[Any, ...]: ...
@overload
def astuple(obj: DataclassInstance, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ...
@overload
def dataclass(cls: None, /) -> Callable[[type[_T]], type[_T]]: ...
def dataclass(
Copy link
Member

Choose a reason for hiding this comment

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

This now duplicates the overload under if sys.version_info >= (3, 11) branch below.


b = Bar(attr="attr")

if dc.is_dataclass(b):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what is_dataclass adds to this test case.

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.

Inconsistent dataclass declaration
2 participants