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

Add type stubs #1259

Draft
wants to merge 45 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
796bb71
Add stub files generated by monkeytype
StefanBrand Apr 27, 2023
6e126e2
Move type stub files into place where mypy auto-detects them
StefanBrand May 4, 2023
c085f47
Mypy: Ignore boto3.session and cligj
StefanBrand May 5, 2023
77e077a
Add FionaDateType to rfc3339 type stub
StefanBrand May 5, 2023
53d7a10
add mypy action
baloola May 5, 2023
546d59d
Add type stubs for ogrext and schema modules
StefanBrand May 5, 2023
254c16a
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola May 5, 2023
b1e3fcf
Typing fixes
constantinius May 5, 2023
68ed509
fix python version
baloola May 5, 2023
0c7a12d
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola May 5, 2023
81324e5
Adding boto3 o module ignores
constantinius May 5, 2023
2410da7
Add type stub for _env
StefanBrand May 5, 2023
e2b277a
Add requirements-types.txt file
StefanBrand May 5, 2023
d4f967a
Add IPython to ignored imports
StefanBrand May 5, 2023
42f9e45
installing Dependencies
baloola May 5, 2023
f38da6b
Merge branch 'types-runtime-monkeytype' of github.com:EOX-A/Fiona int…
baloola May 5, 2023
757586c
fix a typo
baloola May 5, 2023
f8c7818
Adding manual stub for CRS
constantinius May 5, 2023
472f1ec
Adding additional manual stubs
constantinius May 5, 2023
02d68b6
Adding missing stubs
constantinius May 5, 2023
4a82e58
Depend on requirements in requirements-types
StefanBrand May 5, 2023
fb80e6b
Add typed GeoJSON objects
StefanBrand Jun 13, 2023
6f000f9
Add GDALVersion-related type stubs
StefanBrand Jun 20, 2023
406f58d
Adding additional type hints to be installed
constantinius Jun 20, 2023
b26afaa
Extracting additional method interface from main.py
constantinius Jun 20, 2023
70f893f
Fixing type hints in test
constantinius Jun 20, 2023
974d4de
Adding inital type hints for _geometry
constantinius Jun 20, 2023
5d00089
Add stubs for functions in crs module
StefanBrand Jun 20, 2023
604e7d9
fix more types
baloola Jun 20, 2023
0c86f4e
Removing duplicate tests
constantinius Jun 20, 2023
444957f
Fixing import
constantinius Jun 20, 2023
6efb3aa
Adding additional type hint exports for ogrext
constantinius Jun 20, 2023
e8ac269
add type for driver_supports_mode
baloola Jun 20, 2023
dd145b3
Fixing typing for supported_drivers in various re-exports
constantinius Jun 20, 2023
79c5736
Adding type hnt
constantinius Jun 20, 2023
53bd1b1
Adding type stubs installation for setuptools
constantinius Jun 20, 2023
2aa427a
add typing to drvsupport
baloola Jun 20, 2023
8c1dbc7
Correctly type
StefanBrand Jun 20, 2023
5d7de80
Fixing duplicate test
constantinius Jun 20, 2023
15a2585
Trying to fix typing for Features.from_dict
constantinius Jun 20, 2023
39ebbca
Add tests directory to static type checking
StefanBrand Jun 20, 2023
e17ab56
Workaround mypy bug with kwargs
StefanBrand Jun 20, 2023
5cba528
Run mypy-test GitHub Action with Python 3.11
StefanBrand Jun 20, 2023
f305dba
Rename GitHub Action step to make it more generic
StefanBrand Jun 20, 2023
fdcacf9
Add pytest to requirements-types.txt
StefanBrand Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/mypy-test.yaml
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
uses: actions/setup-python@v1
with:
python-version: 3.11
- name: Install Dependencies
run: |
python3 -m pip install -r requirements-types.txt
- name: mypy
run: |
mypy fiona tests
72 changes: 72 additions & 0 deletions fiona/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from io import (
BufferedReader,
BytesIO,
)
from fiona._env import GDALVersion
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,
)

gdal_version: GDALVersion

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: ...


supported_drivers: Dict[str, str]
23 changes: 23 additions & 0 deletions fiona/_env.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import NamedTuple


class GDALDataFinder:
...

class GDALVersion(NamedTuple):
major: int
minor: int
revision: int

class PROJDataFinder:
...

def calc_gdal_version_num(maj: int, min: int, rev: int) -> int: ...

def get_gdal_release_name() -> str: ...

def get_gdal_version_num() -> int: ...

def get_gdal_version_tuple() -> GDALVersion: ...

def get_proj_version_tuple() -> tuple[int, int, int]: ...
8 changes: 8 additions & 0 deletions fiona/_geometry.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Any


class GeomBuilder:
def build_from_feature(self, feature: Any) -> Any: ...


def geometryRT(geom) -> Any: ...
100 changes: 100 additions & 0 deletions fiona/collection.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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: ...


supported_drivers: dict
1 change: 1 addition & 0 deletions fiona/compat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def strencode(instr: str, encoding: str = ...) -> bytes: ...
57 changes: 57 additions & 0 deletions fiona/crs.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import Literal, Tuple, Optional, TypedDict, 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": ...


class CRSDict(TypedDict):
init: str
no_defs: Literal[True]


def from_epsg(code: Union[int, str]) -> CRSDict: ...


def from_string(prjs: str) -> dict: ...


def to_string(crs: dict) -> str: ...
3 changes: 2 additions & 1 deletion fiona/drvsupport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Dict

from fiona.env import Env
from fiona._env import get_gdal_version_tuple
Expand All @@ -13,7 +14,7 @@
# entries for each at https://gdal.org/drivers/vector/index.html to screen
# out the multi-layer formats.

supported_drivers = dict(
supported_drivers: Dict[str, str] = dict(
[
# OGR Vector Formats
# Format Name Code Creation Georeferencing Compiled by default
Expand Down
37 changes: 37 additions & 0 deletions fiona/drvsupport.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from fiona.path import UnparsedPath
from typing import (
Dict,
Union,
Any
)


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]: ...


def _driver_supports_milliseconds(driver: str) -> bool: ...


def _driver_supports_mode(driver: str, mode: Any) -> bool: ...


supported_drivers: Dict[str, str]

driver_mode_mingdal: Dict[str, dict[str, Any]]

_driver_converts_to_str: Dict[str, dict[str, Any]]



3 changes: 3 additions & 0 deletions fiona/enums.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class WktVersion:
@classmethod
def _missing_(cls, value: str): ...
Loading