-
Notifications
You must be signed in to change notification settings - Fork 861
Closed
Description
Contributing guidelines
- I understand the contributing guidelines
Documentation
- My proposal is not addressed by the documentation or examples
Existing issues
- Nothing similar appears in an existing issue
What problem does your feature proposal solve?
Description
When using strict type checkers like pyright/basedpyright, functions in osmnx.distance (and likely elsewhere) that accept nx.MultiDiGraph parameters cause "partially unknown type" warnings because the MultiDiGraph annotation doesn't include a generic type parameter.
Example
from networkx import MultiDiGraph
from osmnx.distance import nearest_nodes
# When the graph is properly typed:
graph: MultiDiGraph[int] = ...
# This triggers a type warning because osmnx expects MultiDiGraph (unparameterized)
# but we're passing MultiDiGraph[int]
nearest_nodes(graph, 1.0, 2.0)Error Message (from basedpyright)
Type of "nearest_nodes" is partially unknown
Type of "nearest_nodes" is "Overload[(G: MultiDiGraph[Unknown], X: float, Y: float) -> int, ...]"
What is your proposed solution?
Suggested Fix
Update the type annotations to use MultiDiGraph[Any] instead of bare MultiDiGraph:
# Current (in distance.py)
def nearest_nodes(G: nx.MultiDiGraph, X: float, Y: float) -> int: ...
# Suggested
from typing import Any
def nearest_nodes(G: nx.MultiDiGraph[Any], X: float, Y: float) -> int: ...This would allow users with typed graphs (MultiDiGraph[int], MultiDiGraph[str], etc.) to pass them without type errors.
What alternatives have you considered?
The alternative is to use ignore directives.
Additional context
Environment
- osmnx version: 2.0.6
- Python version: 3.12
- Type checker: basedpyright
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels