pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.63k stars 1.09k forks source link

Add runtime type checking in CI tests #9745

Open DimitriPapadopoulos opened 2 weeks ago

DimitriPapadopoulos commented 2 weeks ago

This should prevent TYPE_CHECKING misuse.

Fixes #9744.

max-sixty commented 2 weeks ago

This is a good test! Unfortunately our CI fails, and we couldn't work out a succinct way of changing our annotations so that we could resolve #9581.

If there were some way of adding this in part, that would be great. But likely we'll need to wait for more support so we can support this while having just DataArray in the type definition without the full path (more discussion in the attached issue)

headtr1ck commented 1 week ago

Maybe we make it optional, similar to pyright?

DimitriPapadopoulos commented 1 week ago

I was planning on exploring the suggestions in https://github.com/pydata/xarray/issues/9581.

But yes, I could make the test optional for now.

max-sixty commented 1 week ago

Is it helpful to have an optional CI which fails everytime at the first import though?

DimitriPapadopoulos commented 4 days ago

It looks like solutions that might work with beartype fail with MyPy. I haven't been able to find a solution within the little time I can dedicate to this issue.

In any case, it looks like TYPE_CHECKING shouldn't be used, except to avoid circular imports.