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

REF: Rename _MakerCRS to CustomConstructorCRS and make public #912

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/api/crs/crs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ CompoundCRS
:special-members: __init__


CustomConstructorCRS
------------------------

.. autoclass:: pyproj.crs.CustomConstructorCRS
:members:
:show-inheritance:
:special-members: __init__


is_wkt
-----------------

Expand Down
1 change: 1 addition & 0 deletions pyproj/crs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CRS,
BoundCRS,
CompoundCRS,
CustomConstructorCRS,
DerivedGeographicCRS,
GeocentricCRS,
GeographicCRS,
Expand Down
23 changes: 11 additions & 12 deletions pyproj/crs/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,11 +1535,10 @@ def __repr__(self) -> str:
)


class _MakerCRS(CRS):
class CustomConstructorCRS(CRS):
"""
This class exists to handle the oddities to do with the
maker CRS classes having a different constructor than
the base CRS classes.
This class is a base class for CRS classes
that use a different constructor than the main CRS class.

.. versionadded:: 3.2.0

Expand Down Expand Up @@ -1592,7 +1591,7 @@ def from_user_input(cls, value: Any, **kwargs) -> "CRS":
if isinstance(value, cls):
return value
crs = cls.__new__(cls)
super(_MakerCRS, crs).__init__(value, **kwargs)
super(CustomConstructorCRS, crs).__init__(value, **kwargs)
crs._check_type()
return crs

Expand Down Expand Up @@ -1668,7 +1667,7 @@ def to_3d(self, name: Optional[str] = None) -> "CRS":
return CRS(self._crs.to_3d(name=name))


class GeographicCRS(_MakerCRS):
class GeographicCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down Expand Up @@ -1708,7 +1707,7 @@ def __init__(
super().__init__(geographic_crs_json)


class DerivedGeographicCRS(_MakerCRS):
class DerivedGeographicCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down Expand Up @@ -1764,7 +1763,7 @@ def __init__(
super().__init__(derived_geographic_crs_json)


class GeocentricCRS(_MakerCRS):
class GeocentricCRS(CustomConstructorCRS):
"""
.. versionadded:: 3.2.0

Expand Down Expand Up @@ -1819,7 +1818,7 @@ def __init__(
super().__init__(geocentric_crs_json)


class ProjectedCRS(_MakerCRS):
class ProjectedCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down Expand Up @@ -1868,7 +1867,7 @@ def __init__(
super().__init__(proj_crs_json)


class VerticalCRS(_MakerCRS):
class VerticalCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down Expand Up @@ -1916,7 +1915,7 @@ def __init__(
super().__init__(vert_crs_json)


class CompoundCRS(_MakerCRS):
class CompoundCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down Expand Up @@ -1948,7 +1947,7 @@ def __init__(self, name: str, components: List[Any]) -> None:
super().__init__(compound_crs_json)


class BoundCRS(_MakerCRS):
class BoundCRS(CustomConstructorCRS):
"""
.. versionadded:: 2.5.0

Expand Down
20 changes: 20 additions & 0 deletions test/crs/test_crs_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
CRS,
BoundCRS,
CompoundCRS,
CustomConstructorCRS,
DerivedGeographicCRS,
GeocentricCRS,
GeographicCRS,
Expand Down Expand Up @@ -321,3 +322,22 @@ def test_bound_crs_crs__from_methods():
assert_maker_inheritance_valid(
BoundCRS.from_json_dict(CRS(crs_str).to_json_dict()), BoundCRS
)


def test_custom_constructor_crs__not_implemented():
class MyCustomInit(CustomConstructorCRS):
def __init__(self, *, name: str):
super().__init__(name)

with pytest.raises(NotImplementedError):
MyCustomInit.from_epsg(4326)


def test_custom_constructor_crs():
class MyCustomInit(CustomConstructorCRS):
_expected_types = ("Geographic 2D CRS",)

def __init__(self, *, name: str):
super().__init__(name)

assert isinstance(MyCustomInit.from_epsg(4326), MyCustomInit)