-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
I've added some simple test cases for this. Because in my opinion this annotation is very complex. This should be something like: def asdict(obj: Any, *, dict_factory: Callable[[Iterable[Tuple[str, Any]]], _T[str, Any]]) -> _T[str, Any]: ... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here's the |
I am not sure that |
This comment has been minimized.
This comment has been minimized.
Minimal reproducer: from typing import *
T = TypeVar("T")
def f(dict_factory: Callable[[list[tuple[str, Any]]], T]) -> T:
...
f(dict) Error: Mypy correctly infers
We could also try |
This comment has been minimized.
This comment has been minimized.
|
||
|
||
assert_type(dataclasses.astuple(D()), Tuple[Any, ...]) | ||
assert_type(dataclasses.astuple(D(), tuple_factory=tuple), Tuple[Any, ...]) |
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Closing for now due to lack of activity and to keep the number of open PRs manageable. Happy to reopen if you're still interested in working on this! :) |
I have 0 ideas on how to fix it. |
There's a problem with
tuple_factory
anddict_factory
indataclasses.pyi
Why?
Because the given callback type does not really match
tuple
/dict
constructors.Example:
Source: https://github.com/python/cpython/blob/main/Lib/dataclasses.py#L1345-L1349
Closes #8518