Skip to content

Change astuple and asdict factories #8519

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

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if sys.version_info >= (3, 10):
@overload
def asdict(obj: Any) -> dict[str, Any]: ...
@overload
def asdict(obj: Any, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ...
def asdict(obj: Any, *, dict_factory: Callable[[list[tuple[Any, Any]]], _T]) -> _T: ...
@overload
def astuple(obj: Any) -> tuple[Any, ...]: ...
@overload
Expand Down
17 changes: 17 additions & 0 deletions test_cases/stdlib/test_dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# pyright: reportUnnecessaryTypeIgnoreComment=true

import dataclasses
from typing import Any, Dict, Tuple
from typing_extensions import assert_type


@dataclasses.dataclass
class D:
...


assert_type(dataclasses.astuple(D()), Tuple[Any, ...])
assert_type(dataclasses.astuple(D(), tuple_factory=tuple), Tuple[Any, ...])
Copy link
Member

Choose a reason for hiding this comment

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

I think Eric fixed this recently (Any and Unknown being considered different in assert_type()). Let's upgrade pyright to see if it helps.


assert_type(dataclasses.asdict(D()), Dict[str, Any])
assert_type(dataclasses.asdict(D(), dict_factory=dict), Dict[str, Any])