Adds custom typehinting for size (pixel or CRS) arguments
My IDE was complaining about me using an integer for the size parameter, despite that being not only supported, but also the default expected type.
I'm not 100% certain about the naming of the custom type (PixelsOrCRS), or if its addition even hinders readability, but explicitly writing Union[int, float] would make the type hinting very verbose and difficult to read imo.
I think Number would be a better name for Union[int, float].
But more importantly, this seems like a bug in your IDE, not a bug in our type hints. According to PEP 484:
Rather than requiring that users write
import numbersand then usenumbers.Floatetc., this PEP proposes a straightforward shortcut that is almost as effective: when an argument is annotated as having typefloat, an argument of typeintis acceptable
What IDE do you use? Maybe it would be more productive to open an issue with them instead. This doesn't just affect torchgeo.samplers, it affects all Python libraries that use type hints.
What IDE do you use? Maybe it would be more productive to open an issue with them instead. This doesn't just affect
torchgeo.samplers, it affects all Python libraries that use type hints.
@TCherici?
Closing as this is a bug in the IDE, not a bug in TorchGeo or mypy.
Note that a slight change was made to these type hints in #876. Float is more general than int. If ints are input, ints are also returned, not floats.