[rasterio] 1.5.1 support - #16180
Conversation
|
@thomas-maschler I know your away from computer at the moment so won't be able to properly verify, but is this as simple a fix as it should be or is more work required? |
Affine typing| from typing import Any | ||
|
|
||
| @singledispatch | ||
| def to_json(obj: Any) -> Any: ... |
There was a problem hiding this comment.
Is there a better option than Any? Can the return type be str?
There was a problem hiding this comment.
I would like for it to be better than Any but sadly the function is brutally simple:
@singledispatch
def to_json(obj):
"""Convert obj to a JSON serializable form."""
return obj
I guess typing using an unbound Generic would be more effective @thomas-maschler?
There was a problem hiding this comment.
Nope, just looked into it a bit more and singledispatch is already typed in typeshed to tell us this so we'd basically be having a generic typing inside of typing with Callable and generic already. Looks like if we want better typing than Any the next best alternative is object so I've made that change now.
donbarbos
left a comment
There was a problem hiding this comment.
Thank you! Just few suggestions, and could you add DatasetBase.__del__ method _base.pyi:
def __del__(self) -> None: ...|
|
||
| @singledispatch | ||
| def to_json(obj: object) -> object: ... |
There was a problem hiding this comment.
What you about adding TypeVar?
| @singledispatch | |
| def to_json(obj: object) -> object: ... | |
| from typing import TypeVar | |
| _T = TypeVar("_T) | |
| @singledispatch | |
| def to_json(obj: _T) -> _T: ... |
There was a problem hiding this comment.
This does seem like it would be the correct fix, but @singledispatch is already typed in typeshed and it handles the generic side of things as it is a generic function:
def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ...
I did originally think about doing this in this discussion thread, but after looking deeper it was the incorrect change. #16180 (comment)
There was a problem hiding this comment.
Effectively whatever we type it as, the @singledispatch will collapse it to an object anyway if you look into it.
I can't add |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I originally came across this method in the following diff: rasterio/rasterio@1.5.0...1.5.1 |
rasteriohas now released version1.5.1and as a resultaffinehas now released version3.0.0withpy.typedimplemented so we should move to properly typingAffinewith this update.