-
-
Notifications
You must be signed in to change notification settings - Fork 142
Latest typeshed changes break a couple of tests in pandas-stubs #729
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
@twoertwein This might affect internal type checks for the pandas source. |
Thanks @erictraut! As far as I follow, the issue is that Is there still an option to write tailored protocols that differentiate between str/bytes except for typing.IO (which requires way too many methods)? |
I'll take a look at this later today; on first impression I don't understand why my change would break things here. The relevant change should be python/typeshed#10225. |
@erictraut I'm looking at this again now and I think there is a bug in pyright. Consider this example, simplified from the first error you cite above: from typing import overload, Protocol, TypeVar, Any
AnyStr_contra = TypeVar("AnyStr_contra", str, bytes, contravariant=True)
class Buffer(Protocol):
def __bytes__(self) -> bytes:
...
class BytesIO:
def write(self, __b: Buffer) -> None:
pass
class WriteBuffer(Protocol[AnyStr_contra]):
def write(self, __b: AnyStr_contra) -> Any:
...
class NDFrame:
@overload
def to_csv(self, path_or_buf: WriteBuffer[bytes]) -> None:
...
@overload
def to_csv(self, path_or_buf: None = ...) -> str:
...
def to_csv(self, path_or_buf: Any = None) -> Any:
...
def test_types_to_csv() -> None:
df = NDFrame()
df.to_csv(BytesIO()) With pyright 1.1.314 this gives:
Interestingly, if I remove the second overload for |
Thanks for the analysis and simplified rerpo case. This does look like a pyright bug. I've filed a new pyright bug report for tracking purposes. |
Thanks! I haven't looked at the second case you mentioned ( |
I've addressed the issue in pyright, and it will be included in next week's release (1.1.315). It addresses both of the issues I reported in this thread. @JelleZijlstra, apologies for misattributing the problem to the recent typeshed changes. I'll mark this issue closed since there's nothing remaining to do in the |
Can you confirm that the bug is in pyright 1.1.314 ? If so, and someone does a PR prior to release of 1.1.315, we'll have to pin pyright to 1.1.313 until 1.1.315 is released so that the CI works. |
Yes, this bug is in pyright 1.1.314, which also contains the updated typeshed stubs. Pinning to 1.1.313 is a fine temporary workaround. |
Just a heads up that tomorrow's release of pyright 1.1.314 will include the latest typeshed changes. The most significant of these changes are prompted by PEP 688. These changes break a couple of tests in pandas-stubs. You should see the same behaviors with mypy once it ships the next release with an updated typeshed.
The errors are as follows:
test_types_to_csv
(withintest_frame.py
), passing an instance ofio.BytesIO
as the first argument todf.to_csv
no longer works. This is becauseio.BytesIO
no longer satisfies theWriteBuffer[bytes] | WriteBuffer[str]
types defined in the pandas stubs.test_orc_buffer
(withintest_io.py
), the firstcheck
statement fails becausefile_w
is an instance ofio.BufferedWriter
, and this is no longer compatible with theWriteBuffer[bytes]
type defined in the pandas stubs.@JelleZijlstra, for your visibility. I'm guessing that these showed up in the mypy_primer output when the typeshed changes went in?
The text was updated successfully, but these errors were encountered: