Skip to content

Commit

Permalink
Use typing.Self as the returned type of class methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrnz committed Jan 19, 2025
1 parent f1a5c9d commit b13c365
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mapmaker/shapes/line_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from dataclasses import dataclass, field
import itertools
import math
from typing import Any, Optional
from typing import Any, Optional, Self

#===============================================================================

Expand Down Expand Up @@ -50,7 +50,7 @@ class XYPair:
properties: dict[str, Any] = field(default_factory=dict)

@classmethod
def from_coords(cls, coords: Coordinate) -> "XYPair":
def from_coords(cls, coords: Coordinate) -> Self:
self = super().__new__(cls)
self.__init__(coords[0], coords[1])
return self
Expand Down Expand Up @@ -120,7 +120,7 @@ def __hash__(self):
return hash(((self.p0.x, self.p0.y), (self.p1.x, self.p1.y)))

@classmethod
def from_coords(cls, coords: tuple[Coordinate, Coordinate]) -> "Line":
def from_coords(cls, coords: tuple[Coordinate, Coordinate]) -> Self:
self = super().__new__(cls)
self.__init__(XYPair.from_coords(coords[0]), XYPair.from_coords(coords[1]))
return self
Expand Down Expand Up @@ -177,8 +177,8 @@ def __str__(self):
return f'[{self.__x_min}, {self.__x_max}] at {self.__y}'

@classmethod
def from_line(cls, line: Line) -> 'HorizontalLine':
#==================================================
def from_line(cls, line: Line) -> Self:
#======================================
self = super().__new__(cls)
p0 = line.rotation.rotate(line.p0)
p1 = line.rotation.rotate(line.p1)
Expand Down

0 comments on commit b13c365

Please sign in to comment.