-
Notifications
You must be signed in to change notification settings - Fork 102
Wrong return type of read_csv
if using IO-Objects
#87
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
Comments
I think the overloads overall need to be different besides just that one change; reading the implementation and docs, it's dependant on |
I think, you are completely right. I further think, that a first measure should be, to take care of the ReturnValue, which would help others most. As we only have stubs here, I think changing them will not harm. |
I spent way too much time on this today, and then discovered this issue. I'm not sure how python type checking with overloads can do this right. Maybe @jakebailey or @erictraut have some ideas (see example below): The design of the API changes the return type to
So you have to find a way in the overloads to handle all the possible combinations of
To help me figure this out, I wrote a simple test, where @overload
def myfun(fake: str, i1: Literal[True], cs: Literal[None]) -> str:
...
@overload
def myfun(fake: str, i1: Literal[True], cs: int) -> str:
...
@overload
def myfun(fake: str, i1: Literal[True]) -> str:
...
@overload
def myfun(fake: str) -> int:
...
@overload
def myfun(fake: str, i1: Literal[False]) -> int:
...
@overload
def myfun(fake: str, i1: Literal[False], cs: Literal[None]) -> int:
...
@overload
def myfun(fake: str, i1: Literal[False], cs: int) -> str:
...
# @overload
# def myfun(fake: str, i1: bool = False, cs: None = None) -> int:
# ...
# @overload
# def myfun(fake: str, i1: bool = ..., cs: int = ...) -> str:
# ...
def myfun(fake: str, i1: bool = False, cs: Optional[int] = None) -> Union[str, int]:
print(f"i1 is {i1} cs is {cs} result is ", end="")
if i1:
if cs is not None:
return "TextFileReader"
else:
return "TextFileReader"
else:
if cs is not None:
return "TextFileReader"
else:
return -1
res1: int = myfun("meh")
res2: int = myfun("meh", i1=False)
res3: int = myfun("meh", i1=False, cs=None)
res4: str = myfun("meh", i1=False, cs=23)
res5: str = myfun("meh", i1=True)
res6: str = myfun("meh", i1=True, cs=None)
res7: str = myfun("meh", i1=True, cs=23)
res8: int = myfun("meh", cs=None)
res9: str = myfun("meh", cs=23) I could not figure out how to get the last 2 function calls (which correspond to the last 2 lines in the table) to have a proper overload, because in those cases, If someone can show me how to get the above to work, then I could make the changes to |
I think this can be achieved by the following: @overload
def myfun(fake: str, i1: Literal[True], cs: int | None = ...) -> str:
...
@overload
def myfun(fake: str, i1: Literal[False], cs: int) -> str:
...
@overload
def myfun(fake: str, i1: Literal[False] = ..., cs: None = ...) -> int:
...
@overload
def myfun(fake: str, i1: bool = ..., cs: int = ...) -> str:
... |
Thanks @erictraut . That makes pyright happy, but mypy complains. I'll open up an issue there. |
When I send an
StringIO
parameter toread_csv
I get typing errors telling the result would be aTextFileReader
.But this feels completely wrong.
In all my work, it returns a
DataFrame
for example on anStringIO
.Thus I propose to change.
A corresponding pr would come in a few seconds.
The text was updated successfully, but these errors were encountered: