Skip to content

Missing library stubs MYPY #327

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

Open
Jofemago opened this issue Nov 17, 2023 · 4 comments
Open

Missing library stubs MYPY #327

Jofemago opened this issue Nov 17, 2023 · 4 comments

Comments

@Jofemago
Copy link

In the pursuit of using typing to improve error handling in Python, I use mypy to achieve this goal. However, this library poses issues as there is a lack of 'compatibility,' so to speak, and it gives me messages like this:

image

This shouldn't block anyone since in the mypy configuration, an exception can be made using the following line ignore_missing_imports = True in the mypy.ini file.

With this, I could use the Any type for typing, which is bothersome because I would like to specify, for example, a str in the latlng_to_cell function and a tuple[float, float] in the get_center_of_hexagon function.

I would like to know if this is being worked on, will be worked on, or what opinion there is regarding adding typing to this great Python library, especially with mypy.

@RahulDubey391
Copy link

Hi , I would like to take up on the issue.

@Lenormju
Copy link

Lenormju commented Jun 2, 2025

Is this issue still being considered ? If you are interested, I can work on a pull request.

@Jofemago
Copy link
Author

Jofemago commented Jun 3, 2025

@Lenormju Hey, how are you doing? As I mentioned, we overlook missing imports, and we currently run in this manner. However, I am open to helping you if you need assistance. I'm not sure if it's still an issue, but since I've seen this issue is still open, I will determine if it's still active.

@Lenormju
Copy link

Lenormju commented Jun 3, 2025

The issue still exists.
Today I used the H3 lib in my Python project and it worked really fine !
But then I ran mypy on the codebase (to typecheck the code) :

$ uv run --frozen mypy src/ tests/
src/something.py:4: error: Skipping analyzing "h3": module is installed, but missing library stubs or py.typed marker  [import-untyped]
    import h3
    ^
src/something.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 13 source files)

The link explains that :

Mypy will not try inferring the types of any 3rd party libraries you have installed unless they either have declared themselves to be PEP 561 compliant stub package (e.g. with a py.typed file) or have registered themselves on typeshed, the repository of types for the standard library and some 3rd party libraries.

Because I wanted to have type checking immediately, I quickly wrote these typings for the subset of h3-py that I use :

from typing import Literal

def latlng_to_cell(lat: float, lng: float, res: int) -> str: ...

LENGTH_UNITS = Literal["km"] | Literal["m"] | Literal["rads"]

def average_hexagon_edge_length(res: int, unit: str = 'km') -> float: ...

But to solve the problem for everybody else automatically, it would be nice if h3-py had typings.

Currently, the Python code is not typed at all (no type annotations). So there are 2 options :

  • either adding many type annotations to h3-py, and the py.tiped file to indicate to read them
  • either contributing the stubs to typeshed, which won't have any impact on this repository

But it's best not to duplicate the efforts, and because I'm not a maintainer of h3-py, I don't want to make the decision.
Do you have a preference for which direction to follow ?

After that, we'll establish a plan on how to do it, and we'll discuss how you can help me :)

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

No branches or pull requests

3 participants