Skip to content
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

MyPy Compliance #1300

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

MyPy Compliance #1300

wants to merge 13 commits into from

Conversation

trexfeathers
Copy link
Collaborator

🚀 Pull Request

Description


See project item

@github-actions github-actions bot added type: infrastructure Auto-labelled type: examples Auto-labelled for ex/*, example/* and examples/* branches type: cli Auto-labelled labels Jan 29, 2025
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 91.56%. Comparing base (e0009c3) to head (507a228).

Files with missing lines Patch % Lines
src/geovista/bridge.py 66.66% 3 Missing ⚠️
src/geovista/geometry.py 62.50% 3 Missing ⚠️
src/geovista/cache/__init__.py 83.33% 2 Missing ⚠️
src/geovista/geodesic.py 89.47% 2 Missing ⚠️
src/geovista/pantry/textures.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1300      +/-   ##
==========================================
- Coverage   91.64%   91.56%   -0.08%     
==========================================
  Files          59       59              
  Lines        2991     3012      +21     
==========================================
+ Hits         2741     2758      +17     
- Misses        250      254       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/geovista/bridge.py Show resolved Hide resolved
@@ -717,10 +719,10 @@ def from_points(
@classmethod
def from_tiff(
cls,
fname: PathLike,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently PathLike doesn't guarantee the .resolve method.

name: str | None = None,
band: int | None = 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MyPy couldn't cope with this potentially being None, and as far as I could tell it would be impossible for it to be None anyway since it has a default?

Frankly I would have liked to do the same for rgb as well but this triggers Ruff FBT001, which seems fair enough.

if isinstance(fname, str):
fname = Path(fname)

fname = fname.resolve(strict=True)
band = None if rgb else band
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MyPy behaved better with consistent types, and as far as I can see None and -1 are irrelevant anyway given the way rgb is handled.

@@ -1154,8 +1162,7 @@ def from_unstructured(
if not name:
size = data.size // data.shape[-1] if rgb else data.size
name = NAME_POINTS if size == mesh.n_points else NAME_CELLS
if not isinstance(name, str):
name = str(name)
assert isinstance(name, str)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could this ever be any other type? If so what?



def sanitize_data(
*meshes: Iterable[pv.PolyData],
*meshes: pv.PolyData,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I looked this up - the Iterable is implicit with * parameters, which explains why MyPy was unhappy here.

@@ -701,7 +705,7 @@ def _check(option: str) -> bool:
# POI cartesian xyz
self._poi = mesh.center

return super().add_mesh(mesh, **kwargs)
return super().add_mesh(mesh, **kwargs) # type: ignore[misc]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I managed to give GeoPlotterBase various methods using Callable type hints - since we know the intended use in multiple inheritance with a PyVista plotter - but I couldn't see an elegant way of doing anything analogous with references to super(), hence the ignore.

@trexfeathers trexfeathers marked this pull request as ready for review January 29, 2025 17:24
@bjlittle bjlittle self-assigned this Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: cli Auto-labelled type: examples Auto-labelled for ex/*, example/* and examples/* branches type: infrastructure Auto-labelled
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants