From b14d88ea5408e026679ff31b478df555c0ccb1ed Mon Sep 17 00:00:00 2001 From: snowman2 Date: Mon, 10 Apr 2023 20:52:15 -0500 Subject: [PATCH] REF: run pyupgrade with Python 3.9+ --- pyproj/_crs.pyi | 13 +++++++------ pyproj/_crs.pyx | 16 ++++++++-------- pyproj/_geod.pyi | 10 +++++----- pyproj/_transformer.pyi | 10 +++++----- pyproj/_transformer.pyx | 26 +++++++++++++------------- pyproj/aoi.py | 6 +++--- pyproj/crs/crs.py | 40 ++++++++++++++++++++-------------------- pyproj/crs/datum.py | 4 ++-- pyproj/database.pyi | 14 +++++++------- pyproj/database.pyx | 12 ++++++------ pyproj/geod.py | 22 +++++++++++----------- pyproj/list.pyi | 8 +++----- pyproj/proj.py | 8 ++++---- pyproj/sync.py | 20 ++++++++++---------- pyproj/transformer.py | 28 ++++++++++++++-------------- pyproj/utils.py | 10 +++++----- setup.py | 10 +++++----- test/crs/test_crs.py | 2 +- test/test_awips221.py | 6 +++--- test/test_pickle.py | 2 +- test/test_proj.py | 1 - 21 files changed, 133 insertions(+), 135 deletions(-) diff --git a/pyproj/_crs.pyi b/pyproj/_crs.pyi index bc089563c..2edfd860d 100644 --- a/pyproj/_crs.pyi +++ b/pyproj/_crs.pyi @@ -1,4 +1,5 @@ -from typing import Any, Iterable, List, NamedTuple, Optional, Tuple, Union +from collections.abc import Iterable +from typing import Any, NamedTuple, Optional, Union from pyproj.crs.enums import CoordinateOperationType from pyproj.enums import ProjVersion, WktVersion @@ -23,7 +24,7 @@ class AreaOfUse: def __str__(self) -> str: ... def __repr__(self) -> str: ... @property - def bounds(self) -> Tuple[float, float, float, float]: ... + def bounds(self) -> tuple[float, float, float, float]: ... class Base: name: str @@ -115,7 +116,7 @@ class CoordinateSystem(_CRSParts): def from_json_dict(coordinate_system_dict: dict) -> "CoordinateSystem": ... @staticmethod def from_json(coordinate_system_json_str: str) -> "CoordinateSystem": ... - def to_cf(self, rotated_pole: bool = False) -> List[dict]: ... + def to_cf(self, rotated_pole: bool = False) -> list[dict]: ... class Param: name: str @@ -158,7 +159,7 @@ class CoordinateOperation(_CRSParts): @property def towgs84(self) -> Iterable[float]: ... @property - def operations(self) -> Tuple["CoordinateOperation"]: ... + def operations(self) -> tuple["CoordinateOperation"]: ... def __init__(self) -> None: ... def __repr__(self) -> str: ... @staticmethod @@ -199,7 +200,7 @@ class _CRS(Base): @property def area_of_use(self) -> Optional[AreaOfUse]: ... @property - def axis_info(self) -> List[Axis]: ... + def axis_info(self) -> list[Axis]: ... @property def prime_meridian(self) -> Optional[PrimeMeridian]: ... @property @@ -225,7 +226,7 @@ class _CRS(Base): ): ... def list_authority( self, auth_name: Optional[str] = None, min_confidence: int = 70 - ) -> List[AuthorityMatchInfo]: ... + ) -> list[AuthorityMatchInfo]: ... def to_3d(self, name: Optional[str] = None) -> "_CRS": ... def to_2d(self, name: Optional[str] = None) -> "_CRS": ... @property diff --git a/pyproj/_crs.pyx b/pyproj/_crs.pyx index 730b1357c..8facd784f 100644 --- a/pyproj/_crs.pyx +++ b/pyproj/_crs.pyx @@ -706,7 +706,7 @@ cdef class CoordinateSystem(_CRSParts): Returns ------- - List[dict]: + list[dict]: CF-1.8 version of the CoordinateSystem. """ axis_list = self.to_json_dict()["axis"] @@ -2155,7 +2155,7 @@ cdef class CoordinateOperation(_CRSParts): """ Returns ------- - List[Param]: + list[Param]: The coordinate operation parameters. """ if self._params is not None: @@ -2182,7 +2182,7 @@ cdef class CoordinateOperation(_CRSParts): """ Returns ------- - List[Grid]: + list[Grid]: The coordinate operation grids. """ if self._grids is not None: @@ -2243,7 +2243,7 @@ cdef class CoordinateOperation(_CRSParts): """ Returns ------- - List[float]: + list[float]: A list of 3 or 7 towgs84 values if they exist. """ @@ -2273,7 +2273,7 @@ cdef class CoordinateOperation(_CRSParts): Returns ------- - Tuple[CoordinateOperation]: + tuple[CoordinateOperation]: The operations in a concatenated operation. """ @@ -2411,7 +2411,7 @@ cdef class _CRS(Base): Returns ------- - List[Axis]: + list[Axis]: The list of axis information. """ axis_info_list = [] @@ -2643,7 +2643,7 @@ cdef class _CRS(Base): Returns ------- - List[_CRS] + list[_CRS] """ if self._sub_crs_list is not None: return self._sub_crs_list @@ -2856,7 +2856,7 @@ cdef class _CRS(Base): Returns ------- - List[AuthorityMatchInfo]: + list[AuthorityMatchInfo]: List of authority matches for the CRS. """ # get list of possible matching projections diff --git a/pyproj/_geod.pyi b/pyproj/_geod.pyi index e27d1b877..f3e056599 100644 --- a/pyproj/_geod.pyi +++ b/pyproj/_geod.pyi @@ -1,4 +1,4 @@ -from typing import Any, NamedTuple, Tuple, Type +from typing import Any, NamedTuple geodesic_version_str: str @@ -20,7 +20,7 @@ class Geod: def __init__( self, a: float, f: float, sphere: bool, b: float, es: float ) -> None: ... - def __reduce__(self) -> Tuple[Type["Geod"], str]: ... + def __reduce__(self) -> tuple[type["Geod"], str]: ... def __repr__(self) -> str: ... def _fwd( self, @@ -39,7 +39,7 @@ class Geod: dist: float, radians: bool = False, return_back_azimuth: bool = True, - ) -> Tuple[float, float, float]: ... + ) -> tuple[float, float, float]: ... def _inv( self, lons1: Any, @@ -57,7 +57,7 @@ class Geod: lats2: float, radians: bool = False, return_back_azimuth: bool = False, - ) -> Tuple[float, float, float]: ... + ) -> tuple[float, float, float]: ... def _inv_or_fwd_intermediate( self, lon1: float, @@ -78,6 +78,6 @@ class Geod: def _line_length(self, lons: Any, lats: Any, radians: bool = False) -> float: ... def _polygon_area_perimeter( self, lons: Any, lats: Any, radians: bool = False - ) -> Tuple[float, float]: ... + ) -> tuple[float, float]: ... def reverse_azimuth(azi: Any, radians: bool = False) -> None: ... diff --git a/pyproj/_transformer.pyi b/pyproj/_transformer.pyi index 0908829fd..e52584acb 100644 --- a/pyproj/_transformer.pyi +++ b/pyproj/_transformer.pyi @@ -1,12 +1,12 @@ import numbers from array import array -from typing import Any, List, NamedTuple, Optional, Tuple, Union +from typing import Any, NamedTuple, Optional, Union from pyproj._crs import _CRS, AreaOfUse, Base, CoordinateOperation from pyproj.enums import ProjVersion, TransformDirection proj_version_str: str -PROJ_VERSION: Tuple[int, int, int] +PROJ_VERSION: tuple[int, int, int] class AreaOfInterest(NamedTuple): west_lon_degree: float @@ -30,7 +30,7 @@ class Factors(NamedTuple): class _TransformerGroup: _transformers: Any - _unavailable_operations: List[CoordinateOperation] + _unavailable_operations: list[CoordinateOperation] _best_available: bool def __init__( self, @@ -66,7 +66,7 @@ class _Transformer(Base): @property def target_crs(self) -> Optional[_CRS]: ... @property - def operations(self) -> Union[Tuple[CoordinateOperation], None]: ... + def operations(self) -> Union[tuple[CoordinateOperation], None]: ... def get_last_used_operation(self) -> _Transformer: ... @property def is_network_enabled(self) -> bool: ... @@ -129,7 +129,7 @@ class _Transformer(Base): radians: bool = False, errcheck: bool = False, direction: Union[TransformDirection, str] = TransformDirection.FORWARD, - ) -> Tuple[float, float, float, float]: ... + ) -> tuple[float, float, float, float]: ... def _get_factors( self, longitude: Any, latitude: Any, radians: bool, errcheck: bool ) -> Factors: ... diff --git a/pyproj/_transformer.pyx b/pyproj/_transformer.pyx index 13491e08e..2b251179b 100644 --- a/pyproj/_transformer.pyx +++ b/pyproj/_transformer.pyx @@ -77,29 +77,29 @@ See PROJ :c:type:`PJ_FACTORS` documentation. Parameters ---------- -meridional_scale: List[float] +meridional_scale: list[float] Meridional scale at coordinate. -parallel_scale: List[float] +parallel_scale: list[float] Parallel scale at coordinate. -areal_scale: List[float] +areal_scale: list[float] Areal scale factor at coordinate. -angular_distortion: List[float] +angular_distortion: list[float] Angular distortion at coordinate. -meridian_parallel_angle: List[float] +meridian_parallel_angle: list[float] Meridian/parallel angle at coordinate. -meridian_convergence: List[float] +meridian_convergence: list[float] Meridian convergence at coordinate. Sometimes also described as *grid declination*. -tissot_semimajor: List[float] +tissot_semimajor: list[float] Maximum scale factor. -tissot_semiminor: List[float] +tissot_semiminor: list[float] Minimum scale factor. -dx_dlam: List[float] +dx_dlam: list[float] Partial derivative of coordinate. -dx_dphi: List[float] +dx_dphi: list[float] Partial derivative of coordinate. -dy_dlam: List[float] +dy_dlam: list[float] Partial derivative of coordinate. -dy_dphi: List[float] +dy_dphi: list[float] Partial derivative of coordinate. """ @@ -458,7 +458,7 @@ cdef class _Transformer(Base): Returns ------- - Tuple[CoordinateOperation]: + tuple[CoordinateOperation]: The operations in a concatenated operation. """ if self._operations is not None: diff --git a/pyproj/aoi.py b/pyproj/aoi.py index 9278c7484..13132bb59 100644 --- a/pyproj/aoi.py +++ b/pyproj/aoi.py @@ -2,7 +2,7 @@ This module contains the structures related to areas of interest. """ from dataclasses import dataclass -from typing import NamedTuple, Optional, Tuple, Union +from typing import NamedTuple, Optional, Union from pyproj.utils import is_null @@ -56,13 +56,13 @@ class AreaOfUse(NamedTuple): name: Optional[str] = None @property - def bounds(self) -> Tuple[float, float, float, float]: + def bounds(self) -> tuple[float, float, float, float]: """ The bounds of the area of use. Returns ------- - Tuple[float, float, float, float] + tuple[float, float, float, float] west, south, east, and north bounds. """ return self.west, self.south, self.east, self.north diff --git a/pyproj/crs/crs.py b/pyproj/crs/crs.py index be09a4de8..7ccafc975 100644 --- a/pyproj/crs/crs.py +++ b/pyproj/crs/crs.py @@ -7,7 +7,7 @@ import re import threading import warnings -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Optional, Union from pyproj._crs import ( _CRS, @@ -89,7 +89,7 @@ def _prepare_from_proj_string(in_crs_string: str) -> str: # make sure the projection starts with +proj or +init starting_params = ("+init", "+proj", "init", "proj") if not in_crs_string.startswith(starting_params): - kvpairs: List[str] = [] + kvpairs: list[str] = [] first_item_inserted = False for kvpair in in_crs_string.split(): if not first_item_inserted and (kvpair.startswith(starting_params)): @@ -643,7 +643,7 @@ def to_cf( """ # pylint: disable=too-many-branches,too-many-return-statements - cf_dict: Dict[str, Any] = {"crs_wkt": self.to_wkt(wkt_version)} + cf_dict: dict[str, Any] = {"crs_wkt": self.to_wkt(wkt_version)} # handle bound CRS if ( @@ -652,7 +652,7 @@ def to_cf( and self.coordinate_operation.towgs84 and self.source_crs ): - sub_cf: Dict[str, Any] = self.source_crs.to_cf( + sub_cf: dict[str, Any] = self.source_crs.to_cf( wkt_version=wkt_version, errcheck=errcheck, ) @@ -873,7 +873,7 @@ def from_cf( name="undefined", components=[bound_crs or projected_crs, vertical_crs] ) - def cs_to_cf(self) -> List[dict]: + def cs_to_cf(self) -> list[dict]: """ .. versionadded:: 3.0.0 @@ -884,7 +884,7 @@ def cs_to_cf(self) -> List[dict]: Returns ------- - List[dict]: + list[dict]: CF-1.8 version of the coordinate systems. """ cf_axis_list = [] @@ -1033,13 +1033,13 @@ def target_crs(self) -> Optional["CRS"]: ) @property - def sub_crs_list(self) -> List["CRS"]: + def sub_crs_list(self) -> list["CRS"]: """ If the CRS is a compound CRS, it will return a list of sub CRS objects. Returns ------- - List[CRS] + list[CRS] """ return [self.__class__(sub_crs) for sub_crs in self._crs.sub_crs_list] @@ -1089,7 +1089,7 @@ def type_name(self) -> str: return self._crs.type_name @property - def axis_info(self) -> List[Axis]: + def axis_info(self) -> list[Axis]: """ Retrieves all relevant axis information in the CRS. If it is a Bound CRS, it gets the axis list from the Source CRS. @@ -1097,7 +1097,7 @@ def axis_info(self) -> List[Axis]: Returns ------- - List[Axis]: + list[Axis]: The list of axis information. """ return self._crs.axis_info @@ -1369,7 +1369,7 @@ def to_authority(self, auth_name: Optional[str] = None, min_confidence: int = 70 def list_authority( self, auth_name: Optional[str] = None, min_confidence: int = 70 - ) -> List[AuthorityMatchInfo]: + ) -> list[AuthorityMatchInfo]: """ .. versionadded:: 3.2.0 @@ -1404,7 +1404,7 @@ def list_authority( Returns ------- - List[AuthorityMatchInfo]: + list[AuthorityMatchInfo]: List of authority matches for the CRS. """ return self._crs.list_authority( @@ -1559,10 +1559,10 @@ def is_derived(self): def __eq__(self, other: Any) -> bool: return self.equals(other) - def __getstate__(self) -> Dict[str, str]: + def __getstate__(self) -> dict[str, str]: return {"srs": self.srs} - def __setstate__(self, state: Dict[str, Any]): + def __setstate__(self, state: dict[str, Any]): self.__dict__.update(state) self._local = CRSLocal() @@ -1574,7 +1574,7 @@ def __str__(self) -> str: def __repr__(self) -> str: # get axis information - axis_info_list: List[str] = [] + axis_info_list: list[str] = [] for axis in self.axis_info: axis_info_list.extend(["- ", str(axis), "\n"]) axis_info_str = "".join(axis_info_list) @@ -1641,7 +1641,7 @@ class CustomConstructorCRS(CRS): """ @property - def _expected_types(self) -> Tuple[str, ...]: + def _expected_types(self) -> tuple[str, ...]: """ These are the type names of the CRS class that are expected when using the from_* methods. @@ -1728,13 +1728,13 @@ def target_crs(self) -> Optional["CRS"]: return None if self._crs.target_crs is None else CRS(self._crs.target_crs) @property - def sub_crs_list(self) -> List["CRS"]: + def sub_crs_list(self) -> list["CRS"]: """ If the CRS is a compound CRS, it will return a list of sub CRS objects. Returns ------- - List[CRS] + list[CRS] """ return [CRS(sub_crs) for sub_crs in self._crs.sub_crs_list] @@ -2017,13 +2017,13 @@ class CompoundCRS(CustomConstructorCRS): _expected_types = ("Compound CRS",) - def __init__(self, name: str, components: List[Any]) -> None: + def __init__(self, name: str, components: list[Any]) -> None: """ Parameters ---------- name: str The name of the Compound CRS. - components: List[Any], optional + components: list[Any], optional List of CRS to create a Compound Coordinate System. List of anything accepted by :meth:`pyproj.crs.CRS.from_user_input` """ diff --git a/pyproj/crs/datum.py b/pyproj/crs/datum.py index 5b1a6ff92..035138976 100644 --- a/pyproj/crs/datum.py +++ b/pyproj/crs/datum.py @@ -2,7 +2,7 @@ This module is for building datums to be used when building a CRS. """ -from typing import Any, Dict, Optional, Union +from typing import Any, Optional, Union from pyproj._crs import Datum, Ellipsoid, PrimeMeridian @@ -75,7 +75,7 @@ def __new__( The radius in meters. Can only be used alone. Cannot be mixed with other parameters. """ - ellipsoid_json: Dict[str, Union[float, str]] = { + ellipsoid_json: dict[str, Union[float, str]] = { "$schema": "https://proj.org/schemas/v0.2/projjson.schema.json", "type": "Ellipsoid", "name": name, diff --git a/pyproj/database.pyi b/pyproj/database.pyi index fa133a397..9cfca9df9 100644 --- a/pyproj/database.pyi +++ b/pyproj/database.pyi @@ -1,4 +1,4 @@ -from typing import Dict, List, NamedTuple, Optional, Union +from typing import NamedTuple, Optional, Union from pyproj.aoi import AreaOfInterest, AreaOfUse from pyproj.enums import PJType @@ -16,11 +16,11 @@ def get_units_map( auth_name: Optional[str] = None, category: Optional[str] = None, allow_deprecated: bool = False, -) -> Dict[str, Unit]: ... -def get_authorities() -> List[str]: ... +) -> dict[str, Unit]: ... +def get_authorities() -> list[str]: ... def get_codes( auth_name: str, pj_type: Union[PJType, str], allow_deprecated: bool = False -) -> List[str]: ... +) -> list[str]: ... class CRSInfo(NamedTuple): auth_name: str @@ -33,14 +33,14 @@ class CRSInfo(NamedTuple): def query_crs_info( auth_name: Optional[str] = None, - pj_types: Union[PJType, List[PJType], None] = None, + pj_types: Union[PJType, list[PJType], None] = None, area_of_interest: Optional[AreaOfInterest] = None, contains: bool = False, allow_deprecated: bool = False, -) -> List[CRSInfo]: ... +) -> list[CRSInfo]: ... def query_utm_crs_info( datum_name: Optional[str] = None, area_of_interest: Optional[AreaOfInterest] = None, contains: bool = False, -) -> List[CRSInfo]: ... +) -> list[CRSInfo]: ... def get_database_metadata(key: str) -> Optional[str]: ... diff --git a/pyproj/database.pyx b/pyproj/database.pyx index 80c75570c..7c96425a1 100644 --- a/pyproj/database.pyx +++ b/pyproj/database.pyx @@ -65,7 +65,7 @@ def get_authorities(): Returns ------- - List[str]: + list[str]: Authorities in PROJ database. """ cdef PJ_CONTEXT* context = pyproj_context_create() @@ -102,7 +102,7 @@ def get_codes(str auth_name not None, pj_type not None, bint allow_deprecated=Fa Returns ------- - List[str]: + list[str]: Codes associated with authorities in PROJ database. """ cdef PJ_CONTEXT* context = NULL @@ -185,7 +185,7 @@ def query_crs_info( ---------- auth_name: Optional[str], optional The name of the authority. Default is all authorities. - pj_types: Union[pyproj.enums.PJType, List[pyproj.enums.PJType], None], optional + pj_types: Union[pyproj.enums.PJType, list[pyproj.enums.PJType], None], optional The type(s) of CRS to get the information (i.e. the types with CRS in the name). If None is provided, it will use all of types (i.e. PJType.CRS). area_of_interest: Optional[AreaOfInterest], optional @@ -200,7 +200,7 @@ def query_crs_info( Returns ------- - List[CRSInfo]: + list[CRSInfo]: CRS information from the PROJ database. """ cdef PJ_CONTEXT* context = NULL @@ -308,7 +308,7 @@ def query_utm_crs_info( Returns ------- - List[CRSInfo]: + list[CRSInfo]: UTM CRS information from the PROJ database. """ projected_crs = query_crs_info( @@ -385,7 +385,7 @@ def get_units_map(str auth_name=None, str category=None, bint allow_deprecated=F Returns ------- - Dict[str, Unit] + dict[str, Unit] """ cdef const char* c_auth_name = NULL cdef const char* c_category = NULL diff --git a/pyproj/geod.py b/pyproj/geod.py index d41ebe11f..db2c479a0 100644 --- a/pyproj/geod.py +++ b/pyproj/geod.py @@ -19,7 +19,7 @@ import math import warnings -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, Optional, Union from pyproj._geod import Geod as _Geod from pyproj._geod import GeodIntermediateReturn, geodesic_version_str @@ -32,7 +32,7 @@ pj_ellps = get_ellps_map() -def _params_from_ellps_map(ellps: str) -> Tuple[float, float, float, float, bool]: +def _params_from_ellps_map(ellps: str) -> tuple[float, float, float, float, bool]: """ Build Geodesic parameters from PROJ ellips map @@ -43,7 +43,7 @@ def _params_from_ellps_map(ellps: str) -> Tuple[float, float, float, float, bool Returns ------- - Tuple[float, float, float, float, bool] + tuple[float, float, float, float, bool] """ ellps_dict = pj_ellps[ellps] @@ -62,7 +62,7 @@ def _params_from_ellps_map(ellps: str) -> Tuple[float, float, float, float, bool return semi_major_axis, semi_minor_axis, flattening, eccentricity_squared, sphere -def _params_from_kwargs(kwargs: Dict) -> Tuple[float, float, float, float]: +def _params_from_kwargs(kwargs: dict) -> tuple[float, float, float, float]: """ Build Geodesic parameters from input kwargs: @@ -83,7 +83,7 @@ def _params_from_kwargs(kwargs: Dict) -> Tuple[float, float, float, float]: Returns ------- - Tuple[float, float, float, float] + tuple[float, float, float, float] """ semi_major_axis = kwargs["a"] @@ -203,7 +203,7 @@ def __init__(self, initstring: Optional[str] = None, **kwargs) -> None: """ # if initparams is a proj-type init string, # convert to dict. - ellpsd: Dict[str, Union[str, float]] = {} + ellpsd: dict[str, Union[str, float]] = {} if initstring is not None: for kvpair in initstring.split(): # Actually only +a and +b are needed @@ -251,7 +251,7 @@ def fwd( # pylint: disable=invalid-name radians: bool = False, inplace: bool = False, return_back_azimuth: bool = True, - ) -> Tuple[Any, Any, Any]: + ) -> tuple[Any, Any, Any]: """ Forward transformation @@ -343,7 +343,7 @@ def inv( radians: bool = False, inplace: bool = False, return_back_azimuth: bool = True, - ) -> Tuple[Any, Any, Any]: + ) -> tuple[Any, Any, Any]: """ Inverse transformation @@ -436,7 +436,7 @@ def npts( radians: bool = False, initial_idx: int = 1, terminus_idx: int = 1, - ) -> List: + ) -> list: """ .. versionadded:: 3.1.0 initial_idx, terminus_idx @@ -924,7 +924,7 @@ def line_lengths(self, lons: Any, lats: Any, radians: bool = False) -> Any: def polygon_area_perimeter( self, lons: Any, lats: Any, radians: bool = False - ) -> Tuple[float, float]: + ) -> tuple[float, float]: """ .. versionadded:: 2.3.0 @@ -1020,7 +1020,7 @@ def geometry_length(self, geometry, radians: bool = False) -> float: def geometry_area_perimeter( self, geometry, radians: bool = False - ) -> Tuple[float, float]: + ) -> tuple[float, float]: """ .. versionadded:: 2.3.0 diff --git a/pyproj/list.pyi b/pyproj/list.pyi index fe959120e..862333030 100644 --- a/pyproj/list.pyi +++ b/pyproj/list.pyi @@ -1,5 +1,3 @@ -from typing import Dict - -def get_proj_operations_map() -> Dict[str, str]: ... -def get_ellps_map() -> Dict[str, Dict[str, float]]: ... -def get_prime_meridians_map() -> Dict[str, str]: ... +def get_proj_operations_map() -> dict[str, str]: ... +def get_ellps_map() -> dict[str, dict[str, float]]: ... +def get_prime_meridians_map() -> dict[str, str]: ... diff --git a/pyproj/proj.py b/pyproj/proj.py index 872964220..6dd1b66ab 100644 --- a/pyproj/proj.py +++ b/pyproj/proj.py @@ -16,7 +16,7 @@ """ import re import warnings -from typing import Any, Optional, Tuple, Type +from typing import Any, Optional from pyproj._compat import cstrencode from pyproj._transformer import Factors @@ -140,7 +140,7 @@ def __call__( inverse: bool = False, errcheck: bool = False, radians: bool = False, - ) -> Tuple[Any, Any]: + ) -> tuple[Any, Any]: """ Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection @@ -185,7 +185,7 @@ def __call__( Returns ------- - Tuple[Any, Any]: + tuple[Any, Any]: The transformed coordinates. """ if inverse: @@ -294,6 +294,6 @@ def to_latlong(self) -> "Proj": coordinate version of the current projection""" return Proj(self.crs.geodetic_crs) - def __reduce__(self) -> Tuple[Type["Proj"], Tuple[str]]: + def __reduce__(self) -> tuple[type["Proj"], tuple[str]]: """special method that allows pyproj.Proj instance to be pickled""" return self.__class__, (self.crs.srs,) diff --git a/pyproj/sync.py b/pyproj/sync.py index 12a8c9f2f..5d523b91e 100644 --- a/pyproj/sync.py +++ b/pyproj/sync.py @@ -9,7 +9,7 @@ from datetime import datetime from functools import partial from pathlib import Path -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Optional from urllib.request import urlretrieve from pyproj._sync import get_proj_endpoint @@ -17,7 +17,7 @@ from pyproj.datadir import get_data_dir, get_user_data_dir -def _bbox_from_coords(coords: List) -> Optional[BBox]: +def _bbox_from_coords(coords: list) -> Optional[BBox]: """ Get the bounding box from coordinates """ @@ -39,7 +39,7 @@ def _bbox_from_coords(coords: List) -> Optional[BBox]: return coord_bbox -def _bbox_from_geom(geom: Dict[str, Any]) -> Optional[BBox]: +def _bbox_from_geom(geom: dict[str, Any]) -> Optional[BBox]: """ Get the bounding box from geojson geometry """ @@ -76,7 +76,7 @@ def _bbox_from_geom(geom: Dict[str, Any]) -> Optional[BBox]: def _filter_bbox( - feature: Dict[str, Any], bbox: BBox, spatial_test: str, include_world_coverage: bool + feature: dict[str, Any], bbox: BBox, spatial_test: str, include_world_coverage: bool ) -> bool: """ Filter by the bounding box. Designed to use with 'filter' @@ -102,7 +102,7 @@ def _filter_bbox( def _filter_properties( - feature: Dict[str, Any], + feature: dict[str, Any], source_id: Optional[str] = None, area_of_use: Optional[str] = None, filename: Optional[str] = None, @@ -140,7 +140,7 @@ def _is_download_needed(grid_name: str) -> bool: return True -def _filter_download_needed(feature: Dict[str, Any]) -> bool: +def _filter_download_needed(feature: dict[str, Any]) -> bool: """ Filter grids so only those that need to be downloaded are included. """ @@ -187,11 +187,11 @@ def _download_resource_file( pass -def _load_grid_geojson(target_directory=None) -> Dict[str, Any]: +def _load_grid_geojson(target_directory=None) -> dict[str, Any]: """ Returns ------- - Dict[str, Any]: + dict[str, Any]: The PROJ grid data list. """ if target_directory is None: @@ -218,7 +218,7 @@ def get_transform_grid_list( include_world_coverage: bool = True, include_already_downloaded: bool = False, target_directory: Optional[str] = None, -) -> Tuple: +) -> tuple: """ Get a list of transform grids that can be downloaded. @@ -240,7 +240,7 @@ def get_transform_grid_list( Returns ------- - List[Dict[str, Any]]: + list[dict[str, Any]]: A list of geojson data of containing information about features that can be downloaded. """ diff --git a/pyproj/transformer.py b/pyproj/transformer.py index a827294b1..d60ca1775 100644 --- a/pyproj/transformer.py +++ b/pyproj/transformer.py @@ -12,10 +12,11 @@ import warnings from abc import ABC, abstractmethod from array import array +from collections.abc import Iterable, Iterator from dataclasses import dataclass from itertools import chain, islice from pathlib import Path -from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union, overload +from typing import Any, Optional, Union, overload from pyproj import CRS from pyproj._compat import cstrencode @@ -218,7 +219,7 @@ def __init__( self._transformers[iii] = Transformer(TransformerUnsafe(transformer)) @property - def transformers(self) -> List["Transformer"]: + def transformers(self) -> list["Transformer"]: """ list[:obj:`Transformer`]: List of available :obj:`Transformer` @@ -227,7 +228,7 @@ def transformers(self) -> List["Transformer"]: return self._transformers @property - def unavailable_operations(self) -> List[CoordinateOperation]: + def unavailable_operations(self) -> list[CoordinateOperation]: """ list[:obj:`pyproj.crs.CoordinateOperation`]: List of :obj:`pyproj.crs.CoordinateOperation` that are not @@ -336,10 +337,10 @@ def __init__( self._local.transformer = transformer_maker() self._transformer_maker = transformer_maker - def __getstate__(self) -> Dict[str, Any]: + def __getstate__(self) -> dict[str, Any]: return {"_transformer_maker": self._transformer_maker} - def __setstate__(self, state: Dict[str, Any]): + def __setstate__(self, state: dict[str, Any]): self.__dict__.update(state) self._local = TransformerLocal() self._local.transformer = self._transformer_maker() @@ -429,13 +430,13 @@ def scope(self) -> str: return self._transformer.scope @property - def operations(self) -> Optional[Tuple[CoordinateOperation]]: + def operations(self) -> Optional[tuple[CoordinateOperation]]: """ .. versionadded:: 2.4.0 Returns ------- - Tuple[CoordinateOperation]: + tuple[CoordinateOperation]: The operations in a concatenated operation. """ return self._transformer.operations @@ -682,7 +683,7 @@ def transform( # pylint: disable=invalid-name errcheck: bool = False, direction: Union[TransformDirection, str] = TransformDirection.FORWARD, inplace: bool = False, - ) -> Tuple[Any, Any]: + ) -> tuple[Any, Any]: ... @overload @@ -695,7 +696,7 @@ def transform( # pylint: disable=invalid-name errcheck: bool = False, direction: Union[TransformDirection, str] = TransformDirection.FORWARD, inplace: bool = False, - ) -> Tuple[Any, Any, Any]: + ) -> tuple[Any, Any, Any]: ... @overload @@ -709,7 +710,7 @@ def transform( # pylint: disable=invalid-name errcheck: bool = False, direction: Union[TransformDirection, str] = TransformDirection.FORWARD, inplace: bool = False, - ) -> Tuple[Any, Any, Any, Any]: + ) -> tuple[Any, Any, Any, Any]: ... def transform( # pylint: disable=invalid-name @@ -851,7 +852,7 @@ def transform( # pylint: disable=invalid-name # if inputs were lists, tuples or floats, convert back. outx = _convertback(x_data_type, inx) outy = _convertback(y_data_type, iny) - return_data: Tuple[Any, ...] = (outx, outy) + return_data: tuple[Any, ...] = (outx, outy) if inz is not None: return_data += (_convertback(z_data_type, inz),) if intime is not None: @@ -984,8 +985,7 @@ def itransform( errcheck=errcheck, ) - for point in zip(*([iter(buff)] * stride)): - yield point + yield from zip(*([iter(buff)] * stride)) def transform_bounds( self, @@ -997,7 +997,7 @@ def transform_bounds( radians: bool = False, errcheck: bool = False, direction: Union[TransformDirection, str] = TransformDirection.FORWARD, - ) -> Tuple[float, float, float, float]: + ) -> tuple[float, float, float, float]: """ .. versionadded:: 3.1.0 diff --git a/pyproj/utils.py b/pyproj/utils.py index c355273de..2f7f73a21 100644 --- a/pyproj/utils.py +++ b/pyproj/utils.py @@ -4,7 +4,7 @@ import json from array import array from enum import Enum, auto -from typing import Any, Tuple +from typing import Any def is_null(value: Any) -> bool: @@ -63,7 +63,7 @@ class DataType(Enum): ARRAY = auto() -def _copytobuffer_return_scalar(xxx: Any) -> Tuple[array, DataType]: +def _copytobuffer_return_scalar(xxx: Any) -> tuple[array, DataType]: """ Prepares scalar for PROJ C-API: - Makes a copy because PROJ modifies buffer in place @@ -76,7 +76,7 @@ def _copytobuffer_return_scalar(xxx: Any) -> Tuple[array, DataType]: Returns ------- - Tuple[Any, DataType] + tuple[Any, DataType] The copy of the data prepared for the PROJ API & Python Buffer API. """ try: @@ -85,7 +85,7 @@ def _copytobuffer_return_scalar(xxx: Any) -> Tuple[array, DataType]: raise TypeError("input must be a scalar") from None -def _copytobuffer(xxx: Any, inplace: bool = False) -> Tuple[Any, DataType]: +def _copytobuffer(xxx: Any, inplace: bool = False) -> tuple[Any, DataType]: """ Prepares data for PROJ C-API: - Makes a copy because PROJ modifies buffer in place @@ -105,7 +105,7 @@ def _copytobuffer(xxx: Any, inplace: bool = False) -> Tuple[Any, DataType]: Returns ------- - Tuple[Any, DataType] + tuple[Any, DataType] The copy of the data prepared for the PROJ API & Python Buffer API. """ # check for pandas.Series, xarray.DataArray or dask.array.Array diff --git a/setup.py b/setup.py index 2feee551f..304e365af 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ import subprocess import sys from pathlib import Path -from typing import Dict, List, Optional +from typing import Optional from pkg_resources import parse_version from setuptools import Extension, setup @@ -73,7 +73,7 @@ def get_proj_dir() -> Path: return proj_dir -def get_proj_libdirs(proj_dir: Path) -> List[str]: +def get_proj_libdirs(proj_dir: Path) -> list[str]: """ This function finds the library directories """ @@ -93,7 +93,7 @@ def get_proj_libdirs(proj_dir: Path) -> List[str]: return libdirs -def get_proj_incdirs(proj_dir: Path) -> List[str]: +def get_proj_incdirs(proj_dir: Path) -> list[str]: """ This function finds the include directories """ @@ -130,7 +130,7 @@ def get_cythonize_options(): return cythonize_options -def get_libraries(libdirs: List[str]) -> List[str]: +def get_libraries(libdirs: list[str]) -> list[str]: """ This function gets the libraries to cythonize with """ @@ -206,7 +206,7 @@ def get_extension_modules(): ) -def get_package_data() -> Dict[str, List[str]]: +def get_package_data() -> dict[str, list[str]]: """ This function retrieves the package data """ diff --git a/test/crs/test_crs.py b/test/crs/test_crs.py index 9a005fb3b..4062379bb 100644 --- a/test/crs/test_crs.py +++ b/test/crs/test_crs.py @@ -29,7 +29,7 @@ ) -class CustomCRS(object): +class CustomCRS: def to_wkt(self): return CRS.from_epsg(4326).to_wkt() diff --git a/test/test_awips221.py b/test/test_awips221.py index 522d063aa..86efaacb2 100644 --- a/test/test_awips221.py +++ b/test/test_awips221.py @@ -69,7 +69,7 @@ def test_awips221(): ) t2 = perf_counter() print("data in lists:") - print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny)) + print("compute lats/lons for all points on AWIPS 221 grid ({}x{})".format(nx, ny)) print("max/min lons") print(min(lons), max(lons)) print("max/min lats") @@ -81,7 +81,7 @@ def test_awips221(): lons, lats = awips221(xa, ya, inverse=True) t2 = perf_counter() print("data in python arrays:") - print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny)) + print("compute lats/lons for all points on AWIPS 221 grid ({}x{})".format(nx, ny)) print("max/min lons") print(min(lons), max(lons)) print("max/min lats") @@ -91,7 +91,7 @@ def test_awips221(): lons, lats = awips221(x, y, inverse=True) t2 = perf_counter() print("data in a numpy array:") - print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny)) + print("compute lats/lons for all points on AWIPS 221 grid ({}x{})".format(nx, ny)) print("max/min lons") print( numpy.minimum.reduce(numpy.ravel(lons)), numpy.maximum.reduce(numpy.ravel(lons)) diff --git a/test/test_pickle.py b/test/test_pickle.py index e61a8c64b..83b650d01 100644 --- a/test/test_pickle.py +++ b/test/test_pickle.py @@ -52,7 +52,7 @@ def test_pickle(): t1 = perf_counter() lons, lats = awips221(x, y, inverse=True) t2 = perf_counter() - print("compute lats/lons for all points on AWIPS 221 grid (%sx%s)" % (nx, ny)) + print("compute lats/lons for all points on AWIPS 221 grid ({}x{})".format(nx, ny)) print("max/min lons in radians") print( numpy.minimum.reduce(numpy.ravel(lons)), numpy.maximum.reduce(numpy.ravel(lons)) diff --git a/test/test_proj.py b/test/test_proj.py index d269ad8ae..2d978f940 100644 --- a/test/test_proj.py +++ b/test/test_proj.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import concurrent.futures import math import os