3333
3434from collections import namedtuple
3535from collections .abc import Sequence
36+ from typing import List , Tuple
3637
38+ from ._types import AnyNumber
3739from .units import (
3840 cicero ,
3941 cm ,
6668
6769
6870class BaseSize (namedtuple ("__BaseSize" , "width, height" )):
69- __slots__ = []
71+ __slots__ : List [str ] = []
72+ _unit : float = pt
7073
71- def __new__ (cls , width , height ):
72- return super ().__new__ (
73- cls ,
74- _rounders (width , "0.000000" ),
75- _rounders (height , "0.000000" ),
76- )
74+ def __new__ (cls , width : AnyNumber , height : AnyNumber ):
75+ return super ().__new__ (cls , float (width ), float (height ))
7776
7877 def __str__ (self ):
7978 return f"{ self .__class__ .__name__ } (width={ _rounders (self .width , '0' )} , height={ _rounders (self .height , '0' )} )"
8079
8180 @classmethod
82- def from_size (cls , size ):
81+ def from_size (cls , size : Tuple [ AnyNumber , AnyNumber ] ):
8382 """
8483
8584 :param size:
@@ -91,7 +90,7 @@ def from_size(cls, size):
9190
9291 return cls (* size )
9392
94- def landscape (self ):
93+ def landscape (self ) -> "BaseSize" :
9594 """
9695 Returns the pagesize in landscape orientation
9796
@@ -104,7 +103,7 @@ def landscape(self):
104103 else :
105104 return self
106105
107- def is_landscape (self ):
106+ def is_landscape (self ) -> bool :
108107 """
109108 Returns whether the pagesize is in the landscape orientation
110109
@@ -114,7 +113,7 @@ def is_landscape(self):
114113
115114 return self .width >= self .height
116115
117- def portrait (self ):
116+ def portrait (self ) -> "BaseSize" :
118117 """
119118 Returns the pagesize in portrait orientation
120119
@@ -127,7 +126,7 @@ def portrait(self):
127126 else :
128127 return self
129128
130- def is_portrait (self ):
129+ def is_portrait (self ) -> bool :
131130 """
132131 Returns whether the pagesize is in the portrait orientation
133132
@@ -137,7 +136,7 @@ def is_portrait(self):
137136
138137 return self .width < self .height
139138
140- def is_square (self ):
139+ def is_square (self ) -> bool :
141140 """
142141 Returns whether the given pagesize is square
143142
@@ -147,10 +146,8 @@ def is_square(self):
147146
148147 return self .width == self .height
149148
150- _unit = pt
151-
152149 @classmethod
153- def from_pt (cls , size ):
150+ def from_pt (cls , size : "PageSize" ):
154151 """
155152
156153 :param size:
@@ -164,7 +161,7 @@ def from_pt(cls, size):
164161
165162 return cls (size .width / cls ._unit , size .height / cls ._unit )
166163
167- def to_pt (self ):
164+ def to_pt (self ) -> "PageSize" :
168165 """
169166
170167 :return:
@@ -218,7 +215,7 @@ class Size_scaled_point(BaseSize):
218215
219216
220217class PageSize (BaseSize ):
221- __slots__ = []
218+ __slots__ : List [ str ] = []
222219
223220 def __new__ (cls , width , height , unit = pt ):
224221 width , height = convert_from ((width , height ), unit )
0 commit comments