-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add type stubs #194
Closed
Closed
Add type stubs #194
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
136433e
Add type stubs
kylebarron 389e8b3
Switch numpy type to ulonglong
kylebarron 9aabf36
Add test scaffolding
kylebarron c7c0b5d
Working example test
kylebarron a4fd693
Fix setup.py syntax
kylebarron af9fefa
Only run mypy tests on python 3
kylebarron ec07b7d
Quotes
kylebarron d53e98f
Lint
kylebarron 91f0141
Update setup.py
kylebarron e2ca5ea
Import literal from typing_extensions
kylebarron 57393b2
Use mypy ini file
kylebarron 91c1e8a
Fix pytest flag
kylebarron 0bf029a
Turn off fail fast
kylebarron 3fde0a4
Fix fail-fast
kylebarron 6cdd16b
Split tests and type tests
kylebarron 6d7b23c
Fix syntax
kylebarron 5943541
Quote files
kylebarron a7bfca5
Quote both
kylebarron 893fa27
Use bash shell
kylebarron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ jobs: | |
run: flake8 src/h3 setup.py tests | ||
|
||
- name: Coverage | ||
run: pytest --cov=h3 --full-trace --cov-report=xml | ||
run: pytest --cov=h3 --full-trace --cov-report=xml tests/*.py | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[mypy] | ||
ignore_missing_imports = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import basic_int | ||
from . import basic_str | ||
from . import memview_int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from typing import Dict, Iterable, List, Optional, Set, Tuple, TypeVar | ||
|
||
from typing_extensions import Literal | ||
|
||
# Static Types | ||
AreaUnits = Literal['km^2', 'm^2', 'rads^2'] | ||
LengthUnits = Literal['km', 'm', 'rads'] | ||
Resolution = int | ||
GeoBoundary = Tuple[Tuple[float, float], ...] | ||
KRange = int | ||
|
||
# Type variables | ||
H3Cell = TypeVar('H3Cell') | ||
H3Edge = TypeVar('H3Edge') | ||
UnorderedH3Cell = TypeVar('UnorderedH3Cell') | ||
|
||
def versions() -> Dict[str, str]: ... | ||
def string_to_h3(h: str) -> int: ... | ||
def h3_to_string(x: int) -> str: ... | ||
def num_hexagons(resolution: Resolution) -> int: ... | ||
def hex_area(resolution: Resolution, unit: AreaUnits = 'km^2') -> float: ... | ||
def edge_length(resolution: Resolution, unit: LengthUnits = 'km') -> float: ... | ||
def h3_is_valid(h: H3Cell) -> bool: ... | ||
def h3_unidirectional_edge_is_valid(edge: H3Edge) -> bool: ... | ||
def geo_to_h3(lat: float, lng: float, resolution: Resolution) -> H3Cell: ... | ||
def h3_to_geo(h: H3Cell) -> Tuple[float, float]: ... | ||
def h3_get_resolution(h: H3Cell) -> int: ... | ||
def h3_to_parent(h: H3Cell, res: Optional[Resolution] = None) -> int: ... | ||
def h3_distance(h1: H3Cell, h2: H3Cell) -> int: ... | ||
def h3_to_geo_boundary(h: H3Cell, geo_json: bool = False) -> GeoBoundary: ... | ||
def k_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_range(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
|
||
# TODO: fix these | ||
# I tried a return value of Ordered[Unordered[H3Cell]] but didn't | ||
# work. Have not gotten return values of Generic[Generic] to work | ||
def hex_range_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def hex_ranges( | ||
hexes: Iterable[H3Cell], K: KRange | ||
) -> Dict[H3Cell, List[Set[H3Cell]]]: ... | ||
def k_ring_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def h3_to_children(h: H3Cell, res: Optional[Resolution] = None) -> UnorderedH3Cell: ... | ||
def compact(hexes: Iterable[H3Cell]) -> UnorderedH3Cell: ... | ||
def uncompact(hexes: Iterable[H3Cell], res: Resolution) -> UnorderedH3Cell: ... | ||
|
||
# Check this | ||
def h3_set_to_multi_polygon( | ||
hexes: Iterable[H3Cell], geo_json: bool = False | ||
) -> List[List[Tuple[float, float]]]: ... | ||
|
||
# def polyfill_polygon(outer, res, holes=None, lnglat_order=False) -> : ... | ||
# | ||
# def polyfill_geojson(geojson, res) -> : ... | ||
|
||
# def polyfill(geojson, res: int, geo_json_conformant=False) -> : ... | ||
|
||
def h3_is_pentagon(h: H3Cell) -> bool: ... | ||
def h3_get_base_cell(h: H3Cell) -> int: ... | ||
def h3_indexes_are_neighbors(h1: H3Cell, h2: H3Cell) -> bool: ... | ||
def get_h3_unidirectional_edge(origin: H3Cell, destination: H3Cell) -> H3Edge: ... | ||
def get_origin_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_destination_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_h3_indexes_from_unidirectional_edge(e: H3Edge) -> Tuple[H3Cell, H3Cell]: ... | ||
def get_h3_unidirectional_edges_from_hexagon(origin: H3Cell) -> Set[H3Edge]: ... | ||
def get_h3_unidirectional_edge_boundary( | ||
edge: H3Edge, geo_json: bool = False | ||
) -> GeoBoundary: ... | ||
def h3_line(start: H3Cell, end: H3Cell) -> List[H3Cell]: ... | ||
def h3_is_res_class_III(h: H3Cell) -> bool: ... | ||
def h3_is_res_class_iii(h: H3Cell) -> bool: ... | ||
def get_pentagon_indexes(resolution: Resolution) -> Set[H3Cell]: ... | ||
def get_res0_indexes() -> Set[H3Cell]: ... | ||
def h3_to_center_child(h: H3Cell, res: Optional[Resolution] = None) -> H3Cell: ... | ||
def h3_get_faces(h: H3Cell) -> Set[int]: ... | ||
def experimental_h3_to_local_ij(origin: H3Cell, h: H3Cell) -> Tuple[int, int]: ... | ||
def experimental_local_ij_to_h3(origin: H3Cell, i: int, j: int) -> H3Cell: ... | ||
def cell_area(h: H3Cell, unit: AreaUnits = 'km^2') -> float: ... | ||
def exact_edge_length(e: H3Edge, unit: LengthUnits = 'km') -> float: ... | ||
def point_dist( | ||
point1: Tuple[float, float], point2: Tuple[float, float], unit: LengthUnits = 'km' | ||
) -> float: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from typing import Dict, Iterable, List, Optional, Set, Tuple | ||
|
||
from typing_extensions import Literal | ||
|
||
from . import _api | ||
|
||
H3Cell = int | ||
H3Edge = int | ||
UnorderedH3Cell = Set[H3Cell] | ||
|
||
# Should be no changes in each API file below this line | ||
|
||
AreaUnits = Literal['km^2', 'm^2', 'rads^2'] | ||
LengthUnits = Literal['km', 'm', 'rads'] | ||
Resolution = int | ||
GeoBoundary = Tuple[Tuple[float, float], ...] | ||
KRange = int | ||
|
||
def versions() -> Dict[str, str]: ... | ||
def string_to_h3(h: str) -> int: ... | ||
def h3_to_string(x: int) -> str: ... | ||
def num_hexagons(resolution: Resolution) -> int: ... | ||
def hex_area(resolution: Resolution, unit: AreaUnits = 'km^2') -> float: ... | ||
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to avoid repeating the entire API definition after defining H3Cell each time? (As below in the PR?) |
||
def edge_length(resolution: Resolution, unit: LengthUnits = 'km') -> float: ... | ||
def h3_is_valid(h: H3Cell) -> bool: ... | ||
def h3_unidirectional_edge_is_valid(edge: H3Edge) -> bool: ... | ||
def geo_to_h3(lat: float, lng: float, resolution: Resolution) -> H3Cell: ... | ||
def h3_to_geo(h: H3Cell) -> Tuple[float, float]: ... | ||
def h3_get_resolution(h: H3Cell) -> int: ... | ||
def h3_to_parent(h: H3Cell, res: Optional[Resolution] = None) -> int: ... | ||
def h3_distance(h1: H3Cell, h2: H3Cell) -> int: ... | ||
def h3_to_geo_boundary(h: H3Cell, geo_json: bool = False) -> GeoBoundary: ... | ||
def k_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_range(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
|
||
# TODO: fix these | ||
# I tried a return value of Ordered[Unordered[H3Cell]] but didn't | ||
# work. Have not gotten return values of Generic[Generic] to work | ||
def hex_range_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def hex_ranges( | ||
hexes: Iterable[H3Cell], K: KRange | ||
) -> Dict[H3Cell, List[Set[H3Cell]]]: ... | ||
def k_ring_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def h3_to_children(h: H3Cell, res: Optional[Resolution] = None) -> UnorderedH3Cell: ... | ||
def compact(hexes: Iterable[H3Cell]) -> UnorderedH3Cell: ... | ||
def uncompact(hexes: Iterable[H3Cell], res: Resolution) -> UnorderedH3Cell: ... | ||
|
||
# Check this | ||
def h3_set_to_multi_polygon( | ||
hexes: Iterable[H3Cell], geo_json: bool = False | ||
) -> List[List[Tuple[float, float]]]: ... | ||
|
||
# def polyfill_polygon(outer, res, holes=None, lnglat_order=False) -> : ... | ||
# | ||
# def polyfill_geojson(geojson, res) -> : ... | ||
|
||
# def polyfill(geojson, res: int, geo_json_conformant=False) -> : ... | ||
|
||
def h3_is_pentagon(h: H3Cell) -> bool: ... | ||
def h3_get_base_cell(h: H3Cell) -> int: ... | ||
def h3_indexes_are_neighbors(h1: H3Cell, h2: H3Cell) -> bool: ... | ||
def get_h3_unidirectional_edge(origin: H3Cell, destination: H3Cell) -> H3Edge: ... | ||
def get_origin_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_destination_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_h3_indexes_from_unidirectional_edge(e: H3Edge) -> Tuple[H3Cell, H3Cell]: ... | ||
def get_h3_unidirectional_edges_from_hexagon(origin: H3Cell) -> Set[H3Edge]: ... | ||
def get_h3_unidirectional_edge_boundary( | ||
edge: H3Edge, geo_json: bool = False | ||
) -> GeoBoundary: ... | ||
def h3_line(start: H3Cell, end: H3Cell) -> List[H3Cell]: ... | ||
def h3_is_res_class_III(h: H3Cell) -> bool: ... | ||
def h3_is_res_class_iii(h: H3Cell) -> bool: ... | ||
def get_pentagon_indexes(resolution: Resolution) -> Set[H3Cell]: ... | ||
def get_res0_indexes() -> Set[H3Cell]: ... | ||
def h3_to_center_child(h: H3Cell, res: Optional[Resolution] = None) -> H3Cell: ... | ||
def h3_get_faces(h: H3Cell) -> Set[int]: ... | ||
def experimental_h3_to_local_ij(origin: H3Cell, h: H3Cell) -> Tuple[int, int]: ... | ||
def experimental_local_ij_to_h3(origin: H3Cell, i: int, j: int) -> H3Cell: ... | ||
def cell_area(h: H3Cell, unit: AreaUnits = 'km^2') -> float: ... | ||
def exact_edge_length(e: H3Edge, unit: LengthUnits = 'km') -> float: ... | ||
def point_dist( | ||
point1: Tuple[float, float], point2: Tuple[float, float], unit: LengthUnits = 'km' | ||
) -> float: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from typing import Dict, Iterable, List, Optional, Set, Tuple | ||
|
||
from typing_extensions import Literal | ||
|
||
from . import _api | ||
|
||
H3Cell = str | ||
H3Edge = str | ||
UnorderedH3Cell = Set[H3Cell] | ||
|
||
# Should be no changes in each API file below this line | ||
|
||
AreaUnits = Literal['km^2', 'm^2', 'rads^2'] | ||
LengthUnits = Literal['km', 'm', 'rads'] | ||
Resolution = int | ||
GeoBoundary = Tuple[Tuple[float, float], ...] | ||
KRange = int | ||
|
||
def versions() -> Dict[str, str]: ... | ||
def string_to_h3(h: str) -> int: ... | ||
def h3_to_string(x: int) -> str: ... | ||
def num_hexagons(resolution: Resolution) -> int: ... | ||
def hex_area(resolution: Resolution, unit: AreaUnits = 'km^2') -> float: ... | ||
def edge_length(resolution: Resolution, unit: LengthUnits = 'km') -> float: ... | ||
def h3_is_valid(h: H3Cell) -> bool: ... | ||
def h3_unidirectional_edge_is_valid(edge: H3Edge) -> bool: ... | ||
def geo_to_h3(lat: float, lng: float, resolution: Resolution) -> H3Cell: ... | ||
def h3_to_geo(h: H3Cell) -> Tuple[float, float]: ... | ||
def h3_get_resolution(h: H3Cell) -> int: ... | ||
def h3_to_parent(h: H3Cell, res: Optional[Resolution] = None) -> int: ... | ||
def h3_distance(h1: H3Cell, h2: H3Cell) -> int: ... | ||
def h3_to_geo_boundary(h: H3Cell, geo_json: bool = False) -> GeoBoundary: ... | ||
def k_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_range(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
def hex_ring(h: H3Cell, k: KRange = 1) -> UnorderedH3Cell: ... | ||
|
||
# TODO: fix these | ||
# I tried a return value of Ordered[Unordered[H3Cell]] but didn't | ||
# work. Have not gotten return values of Generic[Generic] to work | ||
def hex_range_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def hex_ranges( | ||
hexes: Iterable[H3Cell], K: KRange | ||
) -> Dict[H3Cell, List[Set[H3Cell]]]: ... | ||
def k_ring_distances(h: H3Cell, K: KRange) -> List[Set[H3Cell]]: ... | ||
def h3_to_children(h: H3Cell, res: Optional[Resolution] = None) -> UnorderedH3Cell: ... | ||
def compact(hexes: Iterable[H3Cell]) -> UnorderedH3Cell: ... | ||
def uncompact(hexes: Iterable[H3Cell], res: Resolution) -> UnorderedH3Cell: ... | ||
|
||
# Check this | ||
def h3_set_to_multi_polygon( | ||
hexes: Iterable[H3Cell], geo_json: bool = False | ||
) -> List[List[Tuple[float, float]]]: ... | ||
|
||
# def polyfill_polygon(outer, res, holes=None, lnglat_order=False) -> : ... | ||
# | ||
# def polyfill_geojson(geojson, res) -> : ... | ||
|
||
# def polyfill(geojson, res: int, geo_json_conformant=False) -> : ... | ||
|
||
def h3_is_pentagon(h: H3Cell) -> bool: ... | ||
def h3_get_base_cell(h: H3Cell) -> int: ... | ||
def h3_indexes_are_neighbors(h1: H3Cell, h2: H3Cell) -> bool: ... | ||
def get_h3_unidirectional_edge(origin: H3Cell, destination: H3Cell) -> H3Edge: ... | ||
def get_origin_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_destination_h3_index_from_unidirectional_edge(e: H3Edge) -> H3Cell: ... | ||
def get_h3_indexes_from_unidirectional_edge(e: H3Edge) -> Tuple[H3Cell, H3Cell]: ... | ||
def get_h3_unidirectional_edges_from_hexagon(origin: H3Cell) -> Set[H3Edge]: ... | ||
def get_h3_unidirectional_edge_boundary( | ||
edge: H3Edge, geo_json: bool = False | ||
) -> GeoBoundary: ... | ||
def h3_line(start: H3Cell, end: H3Cell) -> List[H3Cell]: ... | ||
def h3_is_res_class_III(h: H3Cell) -> bool: ... | ||
def h3_is_res_class_iii(h: H3Cell) -> bool: ... | ||
def get_pentagon_indexes(resolution: Resolution) -> Set[H3Cell]: ... | ||
def get_res0_indexes() -> Set[H3Cell]: ... | ||
def h3_to_center_child(h: H3Cell, res: Optional[Resolution] = None) -> H3Cell: ... | ||
def h3_get_faces(h: H3Cell) -> Set[int]: ... | ||
def experimental_h3_to_local_ij(origin: H3Cell, h: H3Cell) -> Tuple[int, int]: ... | ||
def experimental_local_ij_to_h3(origin: H3Cell, i: int, j: int) -> H3Cell: ... | ||
def cell_area(h: H3Cell, unit: AreaUnits = 'km^2') -> float: ... | ||
def exact_edge_length(e: H3Edge, unit: LengthUnits = 'km') -> float: ... | ||
def point_dist( | ||
point1: Tuple[float, float], point2: Tuple[float, float], unit: LengthUnits = 'km' | ||
) -> float: ... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this accept
H3Cell
as input?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this was typed as
int
becauseh3_to_string
always takes anint
, no matter the APIh3-py/src/h3/api/_api_template.py
Lines 100 to 101 in 7364b21