-
Notifications
You must be signed in to change notification settings - Fork 207
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 #1259
Draft
StefanBrand
wants to merge
45
commits into
Toblerity:main
Choose a base branch
from
EOX-A:types-runtime-monkeytype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+972
−41
Draft
Add type stubs #1259
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
796bb71
Add stub files generated by monkeytype
StefanBrand 6e126e2
Move type stub files into place where mypy auto-detects them
StefanBrand c085f47
Mypy: Ignore boto3.session and cligj
StefanBrand 77e077a
Add FionaDateType to rfc3339 type stub
StefanBrand 53d7a10
add mypy action
baloola 546d59d
Add type stubs for ogrext and schema modules
StefanBrand 254c16a
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola b1e3fcf
Typing fixes
constantinius 68ed509
fix python version
baloola 0c7a12d
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola 81324e5
Adding boto3 o module ignores
constantinius 2410da7
Add type stub for _env
StefanBrand e2b277a
Add requirements-types.txt file
StefanBrand d4f967a
Add IPython to ignored imports
StefanBrand 42f9e45
installing Dependencies
baloola f38da6b
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola 757586c
fix a typo
baloola f8c7818
Adding manual stub for CRS
constantinius 472f1ec
Adding additional manual stubs
constantinius 02d68b6
Adding missing stubs
constantinius 4a82e58
Depend on requirements in requirements-types
StefanBrand fb80e6b
Add typed GeoJSON objects
StefanBrand 6f000f9
Add GDALVersion-related type stubs
StefanBrand 406f58d
Adding additional type hints to be installed
constantinius b26afaa
Extracting additional method interface from main.py
constantinius 70f893f
Fixing type hints in test
constantinius 974d4de
Adding inital type hints for _geometry
constantinius 5d00089
Add stubs for functions in crs module
StefanBrand 604e7d9
fix more types
baloola 0c86f4e
Removing duplicate tests
constantinius 444957f
Fixing import
constantinius 6efb3aa
Adding additional type hint exports for ogrext
constantinius e8ac269
add type for driver_supports_mode
baloola dd145b3
Fixing typing for supported_drivers in various re-exports
constantinius 79c5736
Adding type hnt
constantinius 53bd1b1
Adding type stubs installation for setuptools
constantinius 2aa427a
add typing to drvsupport
baloola 8c1dbc7
Correctly type
StefanBrand 5d7de80
Fixing duplicate test
constantinius 15a2585
Trying to fix typing for Features.from_dict
constantinius 39ebbca
Add tests directory to static type checking
StefanBrand e17ab56
Workaround mypy bug with kwargs
StefanBrand 5cba528
Run mypy-test GitHub Action with Python 3.11
StefanBrand f305dba
Rename GitHub Action step to make it more generic
StefanBrand fdcacf9
Add pytest to requirements-types.txt
StefanBrand 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Mypy | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Mypy | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Set up Python 3.10.11 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.10.11 | ||
- name: Install Dependencies | ||
run: | | ||
python3 -m pip install -r requirements-types.txt | ||
- name: mypy | ||
run: | | ||
mypy fiona |
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,66 @@ | ||
from io import ( | ||
BufferedReader, | ||
BytesIO, | ||
) | ||
from fiona.collection import Collection | ||
from fiona.crs import CRS | ||
from fiona.env import Env | ||
from fiona.model import Geometry | ||
from fiona.rfc3339 import FionaDateType | ||
from pathlib import PosixPath | ||
from typing import ( | ||
Any, | ||
Dict, | ||
List, | ||
Optional, | ||
Tuple, | ||
Type, | ||
Union, | ||
) | ||
|
||
|
||
def bounds( | ||
ob: Union[Dict[str, Union[str, List[List[List[int]]]]], Geometry, Dict[str, Union[str, List[List[int]]]], Dict[str, Union[Dict[str, Union[str, List[List[List[float]]]]], str, Dict[str, Optional[Union[float, str, int]]]]], Dict[str, Union[str, List[int]]]] | ||
) -> Union[Tuple[int, int, int, int], Tuple[float, float, float, float]]: ... | ||
|
||
|
||
def drivers(*args, **kwargs) -> Env: ... | ||
|
||
|
||
def listdir(path: Union[int, str]) -> List[str]: ... | ||
|
||
|
||
def listlayers( | ||
fp: Union[BufferedReader, str, int, PosixPath], | ||
vfs: Optional[Union[str, int]] = ..., | ||
**kwargs | ||
) -> List[str]: ... | ||
|
||
|
||
def open( | ||
fp: Union[BytesIO, str, PosixPath, BufferedReader], | ||
mode: str = ..., | ||
driver: Optional[str] = ..., | ||
schema: Optional[Any] = ..., | ||
crs: Optional[Union[CRS, Dict[str, Union[str, bool]], Dict[str, Union[int, bool, str]], str]] = ..., | ||
encoding: Optional[str] = ..., | ||
layer: Optional[Union[str, int]] = ..., | ||
vfs: Optional[str] = ..., | ||
enabled_drivers: Optional[List[str]] = ..., | ||
crs_wkt: Optional[str] = ..., | ||
allow_unsupported_drivers: bool = ..., | ||
**kwargs | ||
) -> Collection: ... | ||
|
||
|
||
def prop_type(text: str) -> Union[Type[int], Type[float], Type[str], Type[FionaDateType]]: ... | ||
|
||
|
||
def prop_width(val: str) -> Optional[int]: ... | ||
|
||
|
||
def remove( | ||
path_or_collection: Union[Collection, str], | ||
driver: Optional[str] = ..., | ||
layer: Optional[Union[str, int]] = ... | ||
) -> None: ... |
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,11 @@ | ||
class GDALDataFinder: | ||
... | ||
|
||
|
||
class PROJDataFinder: | ||
... | ||
|
||
|
||
def get_gdal_release_name() -> str: ... | ||
|
||
def get_proj_version_tuple() -> tuple[int, int, 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,97 @@ | ||
from fiona.crs import CRS | ||
from fiona.model import Feature | ||
from fiona.ogrext import ( | ||
ItemsIterator, | ||
Iterator, | ||
KeysIterator, | ||
) | ||
from fiona.path import ( | ||
ParsedPath, | ||
UnparsedPath, | ||
) | ||
from typing import ( | ||
Any, | ||
Dict, | ||
List, | ||
Optional, | ||
Set, | ||
Tuple, | ||
Union, | ||
) | ||
|
||
|
||
def _get_valid_geom_types(schema: Dict[str, Any], driver: str) -> Set[str]: ... | ||
|
||
|
||
def get_filetype(bytesbuf: bytes) -> str: ... | ||
|
||
|
||
class BytesCollection: | ||
def __init__(self, bytesbuf: Union[bytes, str], **kwds) -> None: ... | ||
def __repr__(self) -> str: ... | ||
def close(self) -> None: ... | ||
|
||
|
||
class Collection: | ||
def __contains__(self, fid: int) -> bool: ... | ||
def __del__(self) -> None: ... | ||
def __enter__(self) -> Union[Collection, BytesCollection]: ... | ||
def __exit__(self, type: None, value: None, traceback: None) -> None: ... | ||
def __getitem__(self, item: Union[int, slice]) -> Union[Feature, List[Feature]]: ... | ||
def __init__( | ||
self, | ||
path: Union[UnparsedPath, int, str, ParsedPath], | ||
mode: Union[int, str] = ..., | ||
driver: Optional[Union[str, int]] = ..., | ||
schema: Optional[Any] = ..., | ||
crs: Optional[Any] = ..., | ||
encoding: Optional[Union[str, int]] = ..., | ||
layer: Optional[Union[str, int, float]] = ..., | ||
vsi: Optional[str] = ..., | ||
archive: Optional[int] = ..., | ||
enabled_drivers: Optional[List[str]] = ..., | ||
crs_wkt: Optional[str] = ..., | ||
ignore_fields: Optional[Union[List[int], List[str]]] = ..., | ||
ignore_geometry: bool = ..., | ||
include_fields: Optional[Union[Tuple[()], List[str]]] = ..., | ||
wkt_version: Optional[str] = ..., | ||
allow_unsupported_drivers: bool = ..., | ||
**kwargs | ||
) -> None: ... | ||
def __iter__(self) -> Iterator: ... | ||
def __len__(self) -> int: ... | ||
def __next__(self) -> Feature: ... | ||
def __repr__(self) -> str: ... | ||
def _check_schema_driver_support(self) -> None: ... | ||
@property | ||
def bounds(self) -> Tuple[float, float, float, float]: ... | ||
def close(self) -> None: ... | ||
@property | ||
def closed(self) -> bool: ... | ||
@property | ||
def crs(self) -> Optional[CRS]: ... | ||
@property | ||
def crs_wkt(self) -> str: ... | ||
@property | ||
def driver(self) -> Optional[str]: ... | ||
def filter(self, *args, **kwds) -> Iterator: ... | ||
def flush(self) -> None: ... | ||
def get(self, item: int) -> Feature: ... | ||
def get_tag_item(self, key: str, ns: Optional[str] = ...) -> Optional[str]: ... | ||
def guard_driver_mode(self) -> None: ... | ||
def items(self, *args, **kwds) -> ItemsIterator: ... | ||
def keys(self, *args, **kwds) -> KeysIterator: ... | ||
@property | ||
def meta(self) -> Dict[str, Union[str, Dict[str, Union[str, Dict[str, str]]], CRS]]: ... | ||
@property | ||
def schema(self) -> Any: ... | ||
def tags(self, ns: Optional[str] = ...) -> Dict[str, str]: ... | ||
def update_tag_item(self, key: str, tag: str, ns: Optional[str] = ...) -> int: ... | ||
def update_tags(self, tags: Dict[str, str], ns: Optional[str] = ...) -> int: ... | ||
def validate_record(self, record: Dict[str, Dict[str, Union[str, Tuple[float, float]]]]) -> bool: ... | ||
def validate_record_geometry(self, record: Dict[str, Dict[str, Union[str, Tuple[float, float]]]]) -> bool: ... | ||
def write( | ||
self, | ||
record: Union[Feature, Dict[str, Union[str, Dict[str, Union[str, Tuple[int, int]]], Dict[str, str]]]] | ||
) -> None: ... | ||
def writerecords(self, records: Any) -> None: ... |
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 @@ | ||
def strencode(instr: str, encoding: str = ...) -> bytes: ... |
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,43 @@ | ||
from typing import Tuple, Optional, Union | ||
|
||
|
||
class CRS: | ||
@property | ||
def data(self) -> dict: ... | ||
@property | ||
def is_valid(self) -> bool: ... | ||
@property | ||
def is_epsg_code(self) -> bool: ... | ||
@property | ||
def wkt(self) -> str: ... | ||
@property | ||
def is_geographic(self) -> bool: ... | ||
@property | ||
def is_projected(self) -> bool: ... | ||
@property | ||
def linear_units(self) -> str: ... | ||
@property | ||
def linear_units_factor(self) -> Tuple[str, float]: ... | ||
@property | ||
def units_factor(self) -> Tuple[str, float]: ... | ||
def to_dict(self, projjson: bool = False) -> dict: ... | ||
def to_proj4(self) -> str: ... | ||
def to_wkt(self, morph_to_esri_dialect: bool = False, version: Optional[str] = None) -> str: ... | ||
def to_epsg(self, confidence_threshold: int = 70) -> Optional[int]: ... | ||
def to_authority(self, confidence_threshold: int = 70) -> Optional[Tuple[str, str]]: ... | ||
def _matches(self, confidence_threshold: int = 70) -> dict: ... | ||
def to_string(self) -> str: ... | ||
@staticmethod | ||
def from_epsg(code: int) -> "CRS": ... | ||
@staticmethod | ||
def from_proj4(proj: str) -> "CRS": ... | ||
@staticmethod | ||
def from_dict(initialdata: Optional[dict] = None, **kwargs) -> "CRS": ... | ||
@staticmethod | ||
def from_wkt(wkt: str, morph_from_esri_dialect: bool = False) -> "CRS": ... | ||
@staticmethod | ||
def from_user_input(value: object, morph_from_esri_dialect: bool = False) -> "CRS": ... | ||
@staticmethod | ||
def from_authority(auth_name: str, code: Union[int, str]) -> "CRS": ... | ||
@staticmethod | ||
def from_string(value: str, morph_from_esri_dialect: bool = False) -> "CRS": ... |
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,20 @@ | ||
from fiona.path import UnparsedPath | ||
from typing import ( | ||
Dict, | ||
Union, | ||
) | ||
|
||
|
||
def _driver_converts_field_type_silently_to_str(driver: str, field_type: str) -> bool: ... | ||
|
||
|
||
def _driver_supports_field(driver: str, field_type: str) -> bool: ... | ||
|
||
|
||
def _driver_supports_timezones(driver: str, field_type: str) -> bool: ... | ||
|
||
|
||
def driver_from_extension(path: Union[str, UnparsedPath]) -> str: ... | ||
|
||
|
||
def vector_driver_extensions() -> Dict[str, str]: ... |
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 @@ | ||
class WktVersion: | ||
@classmethod | ||
def _missing_(cls, value: str): ... |
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,68 @@ | ||
from boto3.session import Session | ||
from fiona.session import ( | ||
AWSSession, | ||
DummySession, | ||
GSSession, | ||
) | ||
from typing import ( | ||
Callable, | ||
Dict, | ||
Optional, | ||
Union, | ||
) | ||
|
||
|
||
def defenv(**options) -> None: ... | ||
|
||
|
||
def delenv() -> None: ... | ||
|
||
|
||
def ensure_env(f: Callable) -> Callable: ... | ||
|
||
|
||
def ensure_env_with_credentials(f: Callable) -> Callable: ... | ||
|
||
|
||
def env_ctx_if_needed() -> Union[NullContextManager, Env]: ... | ||
|
||
|
||
def getenv() -> Dict[str, Union[str, bool]]: ... | ||
|
||
|
||
def hasenv() -> bool: ... | ||
|
||
|
||
def setenv(**options) -> None: ... | ||
|
||
|
||
class Env: | ||
def __enter__(self) -> Env: ... | ||
def __exit__(self, exc_type: None = ..., exc_val: None = ..., exc_tb: None = ...) -> None: ... | ||
def __init__( | ||
self, | ||
session: Optional[Union[GSSession, AWSSession, DummySession, Session]] = ..., | ||
aws_unsigned: bool = ..., | ||
profile_name: None = ..., | ||
session_class: Callable = ..., | ||
**options | ||
) -> None: ... | ||
def credentialize(self) -> None: ... | ||
@classmethod | ||
def default_options(cls) -> Dict[str, bool]: ... | ||
@classmethod | ||
def from_defaults(cls, *args, **kwargs) -> Env: ... | ||
|
||
|
||
class GDALVersion: | ||
def at_least(self, other: str) -> bool: ... | ||
@classmethod | ||
def parse(cls, input: str) -> GDALVersion: ... | ||
@classmethod | ||
def runtime(cls) -> GDALVersion: ... | ||
|
||
|
||
class NullContextManager: | ||
def __enter__(self) -> NullContextManager: ... | ||
def __exit__(self, *args) -> None: ... | ||
def __init__(self) -> None: ... |
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,27 @@ | ||
from click.testing import _NamedTextIOWrapper | ||
from typing import ( | ||
Any, | ||
Dict, | ||
Iterator, | ||
List, | ||
Optional, | ||
Tuple, | ||
Union, | ||
) | ||
from fiona.model import Geometry | ||
|
||
|
||
def eval_feature_expression( | ||
feature: Dict[str, Union[Dict[str, Union[str, List[List[List[float]]]]], str, Dict[str, Optional[Union[float, str, int]]]]], | ||
expression: str | ||
) -> Union[float, bool]: ... | ||
|
||
|
||
def make_ld_context(context_items: Tuple[str]) -> Dict[str, Union[Dict[str, Union[str, Dict[str, str]]], str]]: ... | ||
|
||
|
||
def obj_gen(lines: _NamedTextIOWrapper, object_hook: None = ...) -> Iterator[Any]: ... | ||
|
||
|
||
RecRoundObj = Union[Geometry, int, float, List[Union[Geometry, int, float]]] | ||
def recursive_round(obj: RecRoundObj, precision: float) -> RecRoundObj: ... |
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 @@ | ||
def configure_logging(verbosity: int) -> None: ... |
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.
For complex combinations of basic types, it's probably useful to introduce names for (sub)expressions.
I like the style that the httpx library uses:
https://github.com/encode/httpx/blob/master/httpx/_client.py#L1111