Skip to content

Commit e3fba5a

Browse files
committed
fixing errors and adding type hints
1 parent ca58e87 commit e3fba5a

File tree

13 files changed

+63
-42
lines changed

13 files changed

+63
-42
lines changed

Diff for: geometry/angles/angles/__init__.py

Whitespace-only changes.

Diff for: geometry/angles/angles/angle.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class Angle:
6+
"""
7+
representation of an Angle in degrees (unit of measurement)
8+
"""
9+
10+
degrees: float

Diff for: geometry/angles/coordinate_plane/__init__.py

Whitespace-only changes.

Diff for: geometry/angles/lines/__init__.py

Whitespace-only changes.

Diff for: geometry/shapes/ellipses/circle.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ class Circle(ClosedShape):
3333
TypeError: num_cuts must be a numeric value.
3434
"""
3535

36-
def __init__(self, radius):
36+
def __init__(self, radius: float) -> None:
3737
self.radius = radius
3838
self.origin = 0
3939

40-
def get_diameter(self):
40+
def get_diameter(self) -> float:
4141
return self.radius * 2
4242

43-
def perimeter(self):
43+
def perimeter(self) -> float:
4444
return 2 * math.pi * self.radius
4545

46-
def area(self):
46+
def area(self) -> float:
4747
return math.pi * (self.radius**2)
4848

49-
def is_similar(self, compared_shape):
49+
def is_similar(self, compared_shape: ClosedShape) -> bool:
5050
raise NotImplementedError("Not Implemented")
5151

52-
def split(self):
52+
def split(self) -> float:
5353
raise NotImplementedError("Not Implemented")
5454

5555
def max_parts(self, num_cuts: float) -> float:

Diff for: geometry/shapes/ellipses/ellipse.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ class Ellipse(ClosedShape):
2020
NotImplementedError: Not Implemented
2121
"""
2222

23-
def __init__(self, major_radius, minor_radius):
23+
def __init__(self, major_radius: float, minor_radius: float) -> None:
2424
self.major_radius: float = major_radius
2525
self.minor_radius: float = minor_radius
2626

27-
def perimeter(self):
27+
def perimeter(self) -> float:
2828
return math.pi * (self.major_radius + self.minor_radius)
2929

30-
def area(self):
30+
def area(self) -> float:
3131
return math.pi * self.major_radius * self.minor_radius
3232

33-
def is_similar(self, compared_shape):
33+
def is_similar(self, compared_shape: ClosedShape) -> bool:
3434
raise NotImplementedError("Not Implemented")
3535

36-
def split(self):
36+
def split(self) -> float:
3737
raise NotImplementedError("Not Implemented")

Diff for: geometry/shapes/polygon/polygon.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from geometry.shapes.shape_types.closed_shapes import ClosedShape
22
from geometry.shapes.shape_types.intersecting_self_shapes import IntersectSelfShape
33
from geometry.shapes.side import Side
4+
from typing import TypeVar
5+
6+
PolygonType = TypeVar("PolygonType", bound="Polygon")
47

58

69
class Polygon(ClosedShape, IntersectSelfShape):
@@ -43,26 +46,26 @@ class Polygon(ClosedShape, IntersectSelfShape):
4346
4447
"""
4548

46-
def __init__(self):
49+
def __init__(self) -> None:
4750
self.sides: list[Side] = []
4851

49-
def get_side(self, index):
52+
def get_side(self, index: int) -> Side:
5053
return self.sides[index]
5154

52-
def set_side(self, index, side):
55+
def set_side(self, index: int, side: Side) -> None:
5356
self.sides[index] = side
5457

55-
def add_side(self, side):
58+
def add_side(self, side: Side) -> None:
5659
self.sides.append(side)
5760

58-
def area(self):
61+
def area(self) -> float:
5962
pass
6063

61-
def is_similar(self, compared_shape):
64+
def is_similar(self, compared_shape: PolygonType) -> bool:
6265
pass
6366

64-
def perimeter(self):
67+
def perimeter(self) -> float:
6568
pass
6669

67-
def split(self):
70+
def split(self) -> float:
6871
pass

Diff for: geometry/shapes/polygon/rectangle.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ class Rectangle(Polygon):
2222
NotImplementedError: Not Implemented
2323
"""
2424

25-
def __init__(self, short_side_length, long_side_length):
25+
def __init__(self, short_side_length: float, long_side_length: float) -> None:
2626
super().__init__()
2727
self.short_side = Side([], Angle(90), short_side_length)
2828
self.long_side = Side([], Angle(90), long_side_length)
2929
super().add_side(self.short_side)
3030
super().add_side(self.long_side)
3131

32-
def perimeter(self):
32+
def perimeter(self) -> float:
3333
return (self.short_side.length + self.long_side.length) * 2
3434

35-
def area(self):
35+
def area(self) -> float:
3636
return self.short_side.length * self.long_side.length
3737

38-
def is_similar(self, compared_shape):
38+
def is_similar(self, compared_shape: Polygon) -> bool:
3939
raise NotImplementedError("Not Implemented")
4040

41-
def split(self):
41+
def split(self) -> float:
4242
raise NotImplementedError("Not Implemented")

Diff for: geometry/shapes/polygon/square.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class Square(Rectangle):
1919
NotImplementedError: Not Implemented
2020
"""
2121

22-
def __init__(self, side_length):
22+
def __init__(self, side_length: float) -> None:
2323
super().__init__(side_length, side_length)
2424

25-
def perimeter(self):
25+
def perimeter(self) -> float:
2626
return super().perimeter()
2727

28-
def area(self):
28+
def area(self) -> float:
2929
return super().area()
3030

31-
def is_similar(self, compared_shape):
31+
def is_similar(self, compared_shape: Rectangle) -> bool:
3232
raise NotImplementedError("Not Implemented")
3333

34-
def split(self):
34+
def split(self) -> float:
3535
raise NotImplementedError("Not Implemented")

Diff for: geometry/shapes/shape.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from abc import ABC, abstractmethod
2+
from typing import TypeVar
3+
4+
ShapeType = TypeVar("ShapeType", bound="Shape")
25

36

47
class Shape(ABC):
@@ -9,18 +12,23 @@ class Shape(ABC):
912
"""
1013

1114
@abstractmethod
12-
def is_similar(self, compared_shape):
15+
def is_similar(self, compared_shape: ShapeType) -> bool:
1316
"""
1417
a method for comparing with another shape,
1518
which also implements this interface
1619
"""
1720

1821
@abstractmethod
19-
def split(self):
22+
def split(self) -> float:
2023
"""
2124
a method for splitting a shape
2225
into a certain quantity of pieces,
23-
following a specific algorithm
26+
following a specific algorithm which returns
27+
the amount of pieces after splitting the shape
28+
29+
note: in the future, a separate class might be created,
30+
which will represent a certain part of a shape, because of that
31+
the return type of this method might change
2432
"""
2533

2634
"""

Diff for: geometry/shapes/shape_types/closed_shapes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ class ClosedShape(Shape, ABC):
1111
"""
1212

1313
@abstractmethod
14-
def perimeter(self):
14+
def perimeter(self) -> float:
1515
pass
1616

1717
@abstractmethod
18-
def area(self):
18+
def area(self) -> float:
1919
pass
2020

2121
@abstractmethod
22-
def is_similar(self, compared_shape):
22+
def is_similar(self, compared_shape: Shape) -> bool:
2323
pass
2424

2525
@abstractmethod
26-
def split(self):
26+
def split(self) -> float:
2727
pass

Diff for: geometry/shapes/shape_types/intersecting_self_shapes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ class IntersectSelfShape(Shape, ABC):
1111
"""
1212

1313
@abstractmethod
14-
def perimeter(self):
14+
def perimeter(self) -> float:
1515
pass
1616

1717
@abstractmethod
18-
def area(self):
18+
def area(self) -> float:
1919
pass
2020

2121
@abstractmethod
22-
def is_similar(self, compared_shape):
22+
def is_similar(self, compared_shape: Shape) -> bool:
2323
pass
2424

2525
@abstractmethod
26-
def split(self):
26+
def split(self) -> float:
2727
pass

Diff for: geometry/shapes/shape_types/open_shapes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class OpenShape(Shape, ABC):
1111
"""
1212

1313
@abstractmethod
14-
def is_similar(self, compared_shape):
14+
def is_similar(self, compared_shape: Shape) -> bool:
1515
pass
1616

1717
@abstractmethod
18-
def split(self):
18+
def split(self) -> float:
1919
pass

0 commit comments

Comments
 (0)