Inferring correct overload with kwargs and default arg #6995
davetapley
started this conversation in
General
Replies: 1 comment 1 reply
-
I don't fully understand your use case, but you can definitely use TypedDict and pass all arguments in one typed dict: from typing import TypedDict
import pandas as pd
df = pd.DataFrame()
class ReadCSVNone(TypedDict):
path_or_buf: None
sep: str
# and all the other arguments
kwargs: ReadCSVNone = {"sep": ",", "path_or_buf": None}
reveal_type(df.to_csv(**kwargs)) # str |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm not sure if this is bug, an unsupported edge case, or me making a mistake 😁
pandas
to_csv
has two overloads:path_or_buf
isNone
it returnsstr
None
.It takes quite a lot of kwargs, so for readability I want to build them up in a
dict
first and splat them in with**
, like this:That yields
But if I explicitly give
path_or_buf
then it correctly infersstr
:Thoughts?
Additionally: my
[dict](opts: dict[str, Any])
could be narrowed with PEP 692, so perhaps when that's in then it could figure it out?Beta Was this translation helpful? Give feedback.
All reactions