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

DM-42937: Switch to Self types where appropriate #149

Merged
merged 2 commits into from
Feb 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed MANIFEST.in
Empty file.
5 changes: 2 additions & 3 deletions src/vocutouts/models/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Self

from ..exceptions import InvalidCutoutParameterError
from ..uws.models import JobParameter
Expand All @@ -20,9 +21,7 @@ class CutoutParameters:
"""The cutout stencils to apply."""

@classmethod
def from_job_parameters(
cls, params: list[JobParameter]
) -> CutoutParameters:
def from_job_parameters(cls, params: list[JobParameter]) -> Self:
"""Convert generic UWS parameters to the iamge cutout parameters.

Parameters
Expand Down
10 changes: 5 additions & 5 deletions src/vocutouts/models/stencils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any
from typing import Any, Self

from astropy import units as u
from astropy.coordinates import Angle, SkyCoord
Expand All @@ -17,7 +17,7 @@ class Stencil(ABC):

@classmethod
@abstractmethod
def from_string(cls, params: str) -> Stencil:
def from_string(cls, params: str) -> Self:
"""Parse a string representation of stencil parameters to an object."""

@abstractmethod
Expand All @@ -33,7 +33,7 @@ class CircleStencil(Stencil):
radius: Angle

@classmethod
def from_string(cls, params: str) -> CircleStencil:
def from_string(cls, params: str) -> Self:
ra, dec, radius = (float(p) for p in params.split())
return cls(
center=SkyCoord(ra * u.degree, dec * u.degree, frame="icrs"),
Expand Down Expand Up @@ -62,7 +62,7 @@ class PolygonStencil(Stencil):
vertices: SkyCoord

@classmethod
def from_string(cls, params: str) -> PolygonStencil:
def from_string(cls, params: str) -> Self:
data = [float(p) for p in params.split()]
if len(data) % 2 != 0:
msg = f"Odd number of coordinates in vertex list {params}"
Expand Down Expand Up @@ -93,7 +93,7 @@ class RangeStencil(Stencil):
dec: Range

@classmethod
def from_string(cls, params: str) -> RangeStencil:
def from_string(cls, params: str) -> Self:
ra_min, ra_max, dec_min, dec_max = (float(p) for p in params.split())
return cls(
ra=(ra_min, ra_max),
Expand Down