Skip to content

Commit

Permalink
changing constructor-methods from staticmethods to classmethods
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Maxwell committed May 18, 2021
1 parent 1117367 commit 0231502
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
54 changes: 27 additions & 27 deletions pyproj/crs/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def _crs(self):
self._local.crs = _CRS(self.srs)
return self._local.crs

@staticmethod
def from_authority(auth_name: str, code: Union[str, int]) -> "CRS":
@classmethod
def from_authority(cls, auth_name: str, code: Union[str, int]) -> "CRS":
"""
.. versionadded:: 2.2.0
Expand All @@ -339,10 +339,10 @@ def from_authority(auth_name: str, code: Union[str, int]) -> "CRS":
-------
CRS
"""
return CRS(_prepare_from_authority(auth_name, code))
return cls(_prepare_from_authority(auth_name, code))

@staticmethod
def from_epsg(code: Union[str, int]) -> "CRS":
@classmethod
def from_epsg(cls, code: Union[str, int]) -> "CRS":
"""Make a CRS from an EPSG code
Parameters
Expand All @@ -354,10 +354,10 @@ def from_epsg(code: Union[str, int]) -> "CRS":
-------
CRS
"""
return CRS(_prepare_from_epsg(code))
return cls(_prepare_from_epsg(code))

@staticmethod
def from_proj4(in_proj_string: str) -> "CRS":
@classmethod
def from_proj4(cls, in_proj_string: str) -> "CRS":
"""
.. versionadded:: 2.2.0
Expand All @@ -374,10 +374,10 @@ def from_proj4(in_proj_string: str) -> "CRS":
"""
if not is_proj(in_proj_string):
raise CRSError(f"Invalid PROJ string: {in_proj_string}")
return CRS(_prepare_from_string(in_proj_string))
return cls(_prepare_from_string(in_proj_string))

@staticmethod
def from_wkt(in_wkt_string: str) -> "CRS":
@classmethod
def from_wkt(cls, in_wkt_string: str) -> "CRS":
"""
.. versionadded:: 2.2.0
Expand All @@ -394,10 +394,10 @@ def from_wkt(in_wkt_string: str) -> "CRS":
"""
if not is_wkt(in_wkt_string):
raise CRSError(f"Invalid WKT string: {in_wkt_string}")
return CRS(_prepare_from_string(in_wkt_string))
return cls(_prepare_from_string(in_wkt_string))

@staticmethod
def from_string(in_crs_string: str) -> "CRS":
@classmethod
def from_string(cls, in_crs_string: str) -> "CRS":
"""
Make a CRS from:
Expand All @@ -416,7 +416,7 @@ def from_string(in_crs_string: str) -> "CRS":
-------
CRS
"""
return CRS(_prepare_from_string(in_crs_string))
return cls(_prepare_from_string(in_crs_string))

def to_string(self) -> str:
"""
Expand All @@ -437,8 +437,8 @@ def to_string(self) -> str:
return ":".join(auth_info)
return self.srs

@staticmethod
def from_user_input(value: Any, **kwargs) -> "CRS":
@classmethod
def from_user_input(cls, value: Any, **kwargs) -> "CRS":
"""
Initialize a CRS class instance with:
- PROJ string
Expand All @@ -463,7 +463,7 @@ def from_user_input(value: Any, **kwargs) -> "CRS":
"""
if isinstance(value, CRS):
return value
return CRS(value, **kwargs)
return cls(value, **kwargs)

def get_geod(self) -> Optional[Geod]:
"""
Expand All @@ -480,8 +480,8 @@ def get_geod(self) -> Optional[Geod]:
b=self.ellipsoid.semi_minor_metre,
)

@staticmethod
def from_dict(proj_dict: dict) -> "CRS":
@classmethod
def from_dict(cls, proj_dict: dict) -> "CRS":
"""
.. versionadded:: 2.2.0
Expand All @@ -496,10 +496,10 @@ def from_dict(proj_dict: dict) -> "CRS":
-------
CRS
"""
return CRS(_prepare_from_dict(proj_dict))
return cls(_prepare_from_dict(proj_dict))

@staticmethod
def from_json(crs_json: str) -> "CRS":
@classmethod
def from_json(cls, crs_json: str) -> "CRS":
"""
.. versionadded:: 2.4.0
Expand All @@ -514,10 +514,10 @@ def from_json(crs_json: str) -> "CRS":
-------
CRS
"""
return CRS.from_json_dict(_load_proj_json(crs_json))
return cls.from_json_dict(_load_proj_json(crs_json))

@staticmethod
def from_json_dict(crs_dict: dict) -> "CRS":
@classmethod
def from_json_dict(cls, crs_dict: dict) -> "CRS":
"""
.. versionadded:: 2.4.0
Expand All @@ -532,7 +532,7 @@ def from_json_dict(crs_dict: dict) -> "CRS":
-------
CRS
"""
return CRS(json.dumps(crs_dict))
return cls(json.dumps(crs_dict))

def to_dict(self) -> dict:
"""
Expand Down
16 changes: 9 additions & 7 deletions pyproj/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ def is_network_enabled(self) -> bool:
"""
return self._transformer.is_network_enabled

@staticmethod
@classmethod
def from_proj(
cls,
proj_from: Any,
proj_to: Any,
skip_equivalent: bool = False,
Expand Down Expand Up @@ -461,16 +462,17 @@ def from_proj(
if not isinstance(proj_to, Proj):
proj_to = Proj(proj_to)

return Transformer.from_crs(
return cls.from_crs(
proj_from.crs,
proj_to.crs,
skip_equivalent=skip_equivalent,
always_xy=always_xy,
area_of_interest=area_of_interest,
)

@staticmethod
@classmethod
def from_crs(
cls,
crs_from: Any,
crs_to: Any,
skip_equivalent: bool = False,
Expand Down Expand Up @@ -533,7 +535,7 @@ def from_crs(
stacklevel=2,
)

return Transformer(
return cls(
TransformerFromCRS(
CRS.from_user_input(crs_from).srs,
CRS.from_user_input(crs_to).srs,
Expand All @@ -545,8 +547,8 @@ def from_crs(
)
)

@staticmethod
def from_pipeline(proj_pipeline: str) -> "Transformer":
@classmethod
def from_pipeline(cls, proj_pipeline: str) -> "Transformer":
"""Make a Transformer from a PROJ pipeline string.
https://proj.org/operations/pipeline.html
Expand Down Expand Up @@ -576,7 +578,7 @@ def from_pipeline(proj_pipeline: str) -> "Transformer":
Transformer
"""
return Transformer(TransformerFromPipeline(proj_pipeline))
return cls(TransformerFromPipeline(proj_pipeline))

def transform(
self,
Expand Down

0 comments on commit 0231502

Please sign in to comment.