diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fefbf4039..452244710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,3 +37,7 @@ repos: rev: v2.2.6 hooks: - id: codespell + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.1 + hooks: + - id: ruff diff --git a/pyproj/_crs.pyi b/pyproj/_crs.pyi index b46618de4..49f979231 100644 --- a/pyproj/_crs.pyi +++ b/pyproj/_crs.pyi @@ -12,8 +12,6 @@ class Axis: unit_name: str unit_auth_code: str unit_code: str - def __str__(self) -> str: ... - def __repr__(self) -> str: ... class AreaOfUse: west: float @@ -21,8 +19,6 @@ class AreaOfUse: east: float north: float name: str - def __str__(self) -> str: ... - def __repr__(self) -> str: ... @property def bounds(self) -> tuple[float, float, float, float]: ... @@ -40,14 +36,12 @@ class Base: ) -> str: ... def to_json(self, pretty: bool = False, indentation: int = 2) -> str: ... def to_json_dict(self) -> dict: ... - def __str__(self) -> str: ... - def __repr__(self) -> str: ... - def __eq__(self, other: Any) -> bool: ... + def __eq__(self, other: object) -> bool: ... def is_exact_same(self, other: Any) -> bool: ... class _CRSParts(Base): @classmethod - def from_user_input(cls, user_input: Any) -> "_CRSParts": ... + def from_user_input(cls, user_input: Any) -> _CRSParts: ... class Ellipsoid(_CRSParts): semi_major_metre: float @@ -55,36 +49,36 @@ class Ellipsoid(_CRSParts): is_semi_minor_computed: float inverse_flattening: float @staticmethod - def from_authority(auth_name: str, code: int | str) -> "Ellipsoid": ... + def from_authority(auth_name: str, code: int | str) -> Ellipsoid: ... @staticmethod - def from_epsg(code: int | str) -> "Ellipsoid": ... + def from_epsg(code: int | str) -> Ellipsoid: ... @staticmethod - def from_string(ellipsoid_string: str) -> "Ellipsoid": ... + def from_string(ellipsoid_string: str) -> Ellipsoid: ... @staticmethod - def from_json_dict(ellipsoid_dict: dict) -> "Ellipsoid": ... + def from_json_dict(ellipsoid_dict: dict) -> Ellipsoid: ... @staticmethod - def from_json(ellipsoid_json_str: str) -> "Ellipsoid": ... + def from_json(ellipsoid_json_str: str) -> Ellipsoid: ... @staticmethod - def from_name(ellipsoid_name: str, auth_name: str | None = None) -> "Ellipsoid": ... + def from_name(ellipsoid_name: str, auth_name: str | None = None) -> Ellipsoid: ... class PrimeMeridian(_CRSParts): longitude: float unit_conversion_factor: str unit_name: str @staticmethod - def from_authority(auth_name: str, code: int | str) -> "PrimeMeridian": ... + def from_authority(auth_name: str, code: int | str) -> PrimeMeridian: ... @staticmethod - def from_epsg(code: int | str) -> "PrimeMeridian": ... + def from_epsg(code: int | str) -> PrimeMeridian: ... @staticmethod - def from_string(prime_meridian_string: str) -> "PrimeMeridian": ... + def from_string(prime_meridian_string: str) -> PrimeMeridian: ... @staticmethod - def from_json_dict(prime_meridian_dict: dict) -> "PrimeMeridian": ... + def from_json_dict(prime_meridian_dict: dict) -> PrimeMeridian: ... @staticmethod - def from_json(prime_meridian_json_str: str) -> "PrimeMeridian": ... + def from_json(prime_meridian_json_str: str) -> PrimeMeridian: ... @staticmethod def from_name( prime_meridian_name: str, auth_name: str | None = None - ) -> "PrimeMeridian": ... + ) -> PrimeMeridian: ... class Datum(_CRSParts): type_name: str @@ -93,28 +87,28 @@ class Datum(_CRSParts): @property def prime_meridian(self) -> PrimeMeridian | None: ... @staticmethod - def from_authority(auth_name: str, code: int | str) -> "Datum": ... + def from_authority(auth_name: str, code: int | str) -> Datum: ... @staticmethod - def from_epsg(code: int | str) -> "Datum": ... + def from_epsg(code: int | str) -> Datum: ... @staticmethod - def from_string(datum_string: str) -> "Datum": ... + def from_string(datum_string: str) -> Datum: ... @staticmethod - def from_json_dict(datum_dict: dict) -> "Datum": ... + def from_json_dict(datum_dict: dict) -> Datum: ... @staticmethod - def from_json(datum_json_str: str) -> "Datum": ... + def from_json(datum_json_str: str) -> Datum: ... @staticmethod - def from_name(datum_name: str, auth_name: str | None = None) -> "Datum": ... + def from_name(datum_name: str, auth_name: str | None = None) -> Datum: ... class CoordinateSystem(_CRSParts): def __init__(self) -> None: ... @property def axis_list(self) -> Iterable[Axis]: ... @staticmethod - def from_string(coordinate_system_string: str) -> "CoordinateSystem": ... + def from_string(coordinate_system_string: str) -> CoordinateSystem: ... @staticmethod - def from_json_dict(coordinate_system_dict: dict) -> "CoordinateSystem": ... + def from_json_dict(coordinate_system_dict: dict) -> CoordinateSystem: ... @staticmethod - def from_json(coordinate_system_json_str: str) -> "CoordinateSystem": ... + def from_json(coordinate_system_json_str: str) -> CoordinateSystem: ... def to_cf(self, rotated_pole: bool = False) -> list[dict]: ... class Param: @@ -127,8 +121,6 @@ class Param: unit_auth_name: str unit_code: str unit_category: str - def __str__(self) -> str: ... - def __repr__(self) -> str: ... class Grid: short_name: str @@ -138,8 +130,6 @@ class Grid: direct_download: str open_license: str available: str - def __str__(self) -> str: ... - def __repr__(self) -> str: ... class CoordinateOperation(_CRSParts): method_name: str @@ -158,19 +148,18 @@ 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 - def from_authority(auth_name: str, code: int | str) -> "CoordinateOperation": ... + def from_authority(auth_name: str, code: int | str) -> CoordinateOperation: ... @staticmethod - def from_epsg(code: int | str) -> "CoordinateOperation": ... + def from_epsg(code: int | str) -> CoordinateOperation: ... @staticmethod - def from_string(ellipsoid_string: str) -> "CoordinateOperation": ... + def from_string(ellipsoid_string: str) -> CoordinateOperation: ... @staticmethod - def from_json_dict(ellipsoid_dict: dict) -> "CoordinateOperation": ... + def from_json_dict(ellipsoid_dict: dict) -> CoordinateOperation: ... @staticmethod - def from_json(ellipsoid_json_str: str) -> "CoordinateOperation": ... + def from_json(ellipsoid_json_str: str) -> CoordinateOperation: ... def to_proj4(self, version: ProjVersion | int = ProjVersion.PROJ_5) -> str: ... @staticmethod def from_name( @@ -179,7 +168,7 @@ class CoordinateOperation(_CRSParts): coordinate_operation_type: ( CoordinateOperationType | str ) = CoordinateOperationType.CONVERSION, - ) -> "CoordinateOperation": ... + ) -> CoordinateOperation: ... class AuthorityMatchInfo(NamedTuple): auth_name: str @@ -201,13 +190,13 @@ class _CRS(Base): @property def datum(self) -> Datum | None: ... @property - def sub_crs_list(self) -> Iterable["_CRS"]: ... + def sub_crs_list(self) -> Iterable[_CRS]: ... @property - def source_crs(self) -> Optional["_CRS"]: ... + def source_crs(self) -> Optional[_CRS]: ... @property - def target_crs(self) -> Optional["_CRS"]: ... + def target_crs(self) -> Optional[_CRS]: ... @property - def geodetic_crs(self) -> Optional["_CRS"]: ... + def geodetic_crs(self) -> Optional[_CRS]: ... @property def coordinate_system(self) -> CoordinateSystem | None: ... @property @@ -218,8 +207,8 @@ class _CRS(Base): def list_authority( self, auth_name: str | None = None, min_confidence: int = 70 ) -> list[AuthorityMatchInfo]: ... - def to_3d(self, name: str | None = None) -> "_CRS": ... - def to_2d(self, name: str | None = None) -> "_CRS": ... + def to_3d(self, name: str | None = None) -> _CRS: ... + def to_2d(self, name: str | None = None) -> _CRS: ... @property def is_geographic(self) -> bool: ... @property @@ -237,7 +226,7 @@ class _CRS(Base): def equals(self, other: Any, ignore_axis_order: bool) -> bool: ... @property def is_deprecated(self) -> bool: ... - def get_non_deprecated(self) -> list["_CRS"]: ... + def get_non_deprecated(self) -> list[_CRS]: ... def is_proj(proj_string: str) -> bool: ... def is_wkt(proj_string: str) -> bool: ... diff --git a/pyproj/_geod.pyi b/pyproj/_geod.pyi index c417558e8..981c05c10 100644 --- a/pyproj/_geod.pyi +++ b/pyproj/_geod.pyi @@ -20,8 +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 __repr__(self) -> str: ... + def __reduce__(self) -> tuple[type[Geod], str]: ... def _fwd( self, lons: Any, diff --git a/pyproj/_transformer.pyi b/pyproj/_transformer.pyi index 21d5960e0..32fc154e5 100644 --- a/pyproj/_transformer.pyi +++ b/pyproj/_transformer.pyi @@ -83,9 +83,9 @@ class _Transformer(Base): allow_ballpark: bool | None = None, force_over: bool = False, only_best: bool | None = None, - ) -> "_Transformer": ... + ) -> _Transformer: ... @staticmethod - def from_pipeline(proj_pipeline: bytes) -> "_Transformer": ... + def from_pipeline(proj_pipeline: bytes) -> _Transformer: ... def _transform( self, inx: Any, diff --git a/pyproj/aoi.py b/pyproj/aoi.py index cb1caa06c..eea2cc95c 100644 --- a/pyproj/aoi.py +++ b/pyproj/aoi.py @@ -69,7 +69,7 @@ def bounds(self) -> tuple[float, float, float, float]: return self.west, self.south, self.east, self.north def __str__(self) -> str: - return f"- name: {self.name}\n" f"- bounds: {self.bounds}" + return f"- name: {self.name}\n- bounds: {self.bounds}" @dataclass diff --git a/pyproj/crs/crs.py b/pyproj/crs/crs.py index 445a19de3..6ebded896 100644 --- a/pyproj/crs/crs.py +++ b/pyproj/crs/crs.py @@ -1590,7 +1590,7 @@ def get_non_deprecated(self) -> list["CRS"]: """ return self._crs.get_non_deprecated() - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: return self.equals(other) def __getstate__(self) -> dict[str, str]: diff --git a/pyproj/geod.py b/pyproj/geod.py index ea3dc76b3..39f7fb93e 100644 --- a/pyproj/geod.py +++ b/pyproj/geod.py @@ -1114,7 +1114,7 @@ def __repr__(self) -> str: # no ellipse name found, call super class return super().__repr__() - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: """ equality operator == for Geod objects diff --git a/pyproj/transformer.py b/pyproj/transformer.py index e3d0775e2..3e878cb85 100644 --- a/pyproj/transformer.py +++ b/pyproj/transformer.py @@ -1167,7 +1167,7 @@ def __repr__(self) -> str: f"Area of Use:\n{self.area_of_use or '- undefined'}" ) - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: object) -> bool: if not isinstance(other, Transformer): return False return self._transformer.__eq__(other._transformer) diff --git a/pyproject.toml b/pyproject.toml index 6cbc5972c..195d2c32c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,97 @@ version = {attr = "pyproj.__version__"} [tool.black] target_version = ["py310"] + +[tool.ruff] +line-length = 88 +target-version = "py310" +fix = true + +[tool.ruff.lint] +unfixable = [] + +select = [ + # pyflakes + "F", + # pycodestyle + "E", "W", + # flake8-2020 + "YTT", + # flake8-bugbear + "B", + # flake8-quotes + "Q", + # flake8-debugger + "T10", + # flake8-gettext + "INT", + # pylint +# "PL", + # flake8-pytest-style +# "PT", + # misc lints + "PIE", + # flake8-pyi + "PYI", + # tidy imports + "TID", + # implicit string concatenation + "ISC", + # type-checking imports + "TCH", + # comprehensions + "C4", + # pygrep-hooks + "PGH", + # Ruff-specific rules + "RUF", + # flake8-bandit: exec-builtin + "S102", + # numpy-legacy-random + "NPY002", + # Perflint + "PERF", + # flynt + "FLY", + # flake8-logging-format + "G", + # flake8-future-annotations + "FA", + # flake8-slots + "SLOT", + # flake8-raise + "RSE" +] + +ignore = [ + ### Intentionally disabled + # Line too long + "E501", + # Unnecessary `dict` call (rewrite as a literal) + "C408", + # Consider iterable unpacking instead of concatenation + "RUF005", + # No explicit `stacklevel` keyword argument found + "B028", + # Unused `noqa` directive # Only work if ruff is the solve linter/formatter + "RUF100", + # `zip()` without an explicit `strict=` parameter + "B905", + # Only simple default values allowed for typed arguments + "PYI011", + + ### TODO: Enable gradually + # Rename unused + "B007", + # Use specific rule codes when ignoring type issues + "PGH003", + # unconventional-import-alias + "ICN001", + # Move standard library import into a type-checking block + "TCH003", + # Consider f-string instead of string join + "FLY002", + # Use a list comprehension to create a transformed list + "PERF401" + +]