Skip to content

[rasterio] 1.5.1 support - #16180

Open
jack-volantautonomy wants to merge 11 commits into
python:mainfrom
jack-volantautonomy:rasterio_Add-proper-affine-typing
Open

[rasterio] 1.5.1 support#16180
jack-volantautonomy wants to merge 11 commits into
python:mainfrom
jack-volantautonomy:rasterio_Add-proper-affine-typing

Conversation

@jack-volantautonomy

@jack-volantautonomy jack-volantautonomy commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

rasterio has now released version 1.5.1 and as a result affine has now released version 3.0.0 with py.typed implemented so we should move to properly typing Affine with this update.

@jack-volantautonomy

Copy link
Copy Markdown
Contributor Author

@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?

@jack-volantautonomy jack-volantautonomy changed the title [rasterio] Add proper Affine typing [rasterio] 1.5.1 support Aug 10, 2026
@jack-volantautonomy jack-volantautonomy changed the title [rasterio] 1.5.1 support [rasterio] 1.5.1 support (BLOCKED) Aug 10, 2026
Comment thread stubs/rasterio/rasterio/serde.pyi Outdated
from typing import Any

@singledispatch
def to_json(obj: Any) -> Any: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better option than Any? Can the return type be str?

@jack-volantautonomy jack-volantautonomy Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@jack-volantautonomy jack-volantautonomy Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 donbarbos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Just few suggestions, and could you add DatasetBase.__del__ method _base.pyi:

    def __del__(self) -> None: ...

Comment thread stubs/rasterio/METADATA.toml Outdated
Comment thread stubs/rasterio/rasterio/_warp.pyi Outdated
Comment on lines +2 to +4

@singledispatch
def to_json(obj: object) -> object: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you about adding TypeVar?

Suggested change
@singledispatch
def to_json(obj: object) -> object: ...
from typing import TypeVar
_T = TypeVar("_T)
@singledispatch
def to_json(obj: _T) -> _T: ...

@jack-volantautonomy jack-volantautonomy Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectively whatever we type it as, the @singledispatch will collapse it to an object anyway if you look into it.

@jack-volantautonomy jack-volantautonomy changed the title [rasterio] 1.5.1 support (BLOCKED) [rasterio] 1.5.1 support Aug 14, 2026
@jack-volantautonomy

Copy link
Copy Markdown
Contributor Author

Thank you! Just few suggestions, and could you add DatasetBase.__del__ method _base.pyi:

    def __del__(self) -> None: ...

I can't add DataBase.__del__ as this was a commit that got merged yesterday and was not part of the 1.5.1 release this PR intends to support.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@donbarbos

Copy link
Copy Markdown
Contributor

I can't add DataBase.__del__ as this was a commit that got merged yesterday and was not part of the 1.5.1 release this PR intends to support.

I originally came across this method in the following diff: rasterio/rasterio@1.5.0...1.5.1
The commit was made on August 6, and it's included in the 1.5.1 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants