11from __future__ import annotations
22
33import re
4+ from typing import Iterable
45
56from packaging .specifiers import InvalidSpecifier
67from packaging .version import Version , parse
1617
1718class RangeSpecifier :
1819 _specs : set
20+ join_type : JoinTypes
1921
20- def __init__ (self , spec = None ):
22+ def __init__ (self , spec : object | None = None ) -> None :
2123 if not spec :
2224 self ._specs = set ()
2325 self .join_type = JoinTypes .AND
@@ -42,7 +44,7 @@ def __init__(self, spec=None):
4244 return
4345
4446 @classmethod
45- def _parse (cls , spec ) -> set [Specifier ]:
47+ def _parse (cls , spec : object ) -> set [Specifier ]:
4648 spec = cls ._split_specifier (spec )
4749 result = set ()
4850 for constr in spec :
@@ -74,7 +76,7 @@ def _parse(cls, spec) -> set[Specifier]:
7476 return result
7577
7678 @staticmethod
77- def _split_specifier (spec ) -> list [str ]:
79+ def _split_specifier (spec : object ) -> list [str ]:
7880 if isinstance (spec , (list , tuple )):
7981 return list (spec )
8082 spec = str (spec )
@@ -169,7 +171,7 @@ def _parse_npm(constr: str) -> set[Specifier]:
169171 left += '.' + '' .join (map (str , version .pre ))
170172 return {Specifier ('>=' + left ), Specifier ('==' + right )}
171173
172- def attach_time (self , releases ) -> bool :
174+ def attach_time (self , releases : Iterable ) -> bool :
173175 """Attach time to all specifiers if possible
174176 """
175177 ok = False
@@ -247,27 +249,27 @@ def python_compat(self) -> bool:
247249
248250 # magic methods
249251
250- def __add__ (self , other ) :
252+ def __add__ (self , other : object ) -> RangeSpecifier :
251253 new = self .copy ()
252254 attached = new ._attach (other )
253255 if attached :
254256 return new
255257 return NotImplemented
256258
257- def __radd__ (self , other ) :
259+ def __radd__ (self , other : object ) -> RangeSpecifier :
258260 new = self .copy ()
259261 attached = new ._attach (other )
260262 if attached :
261263 return new
262264 return NotImplemented
263265
264- def __iadd__ (self , other ) :
266+ def __iadd__ (self , other : object ) -> RangeSpecifier :
265267 attached = self ._attach (other )
266268 if attached :
267269 return self
268270 return NotImplemented
269271
270- def _attach (self , other ) -> bool :
272+ def _attach (self , other : object ) -> bool :
271273 if isinstance (other , GitSpecifier ):
272274 self ._specs .add (other )
273275 return True
@@ -316,34 +318,34 @@ def _attach(self, other) -> bool:
316318 self ._specs = new_specs
317319 return True
318320
319- def __contains__ (self , release ) -> bool :
321+ def __contains__ (self , release : object ) -> bool :
320322 rule = all if self .join_type == JoinTypes .AND else any
321323 return rule ((release in specifier ) for specifier in self ._specs )
322324
323- def __str__ (self ):
325+ def __str__ (self ) -> str :
324326 if not self ._specs :
325327 return ''
326328 sep = ',' if self .join_type == JoinTypes .AND else ' || '
327329 return sep .join (sorted (map (str , self ._specs )))
328330
329- def __repr__ (self ):
331+ def __repr__ (self ) -> str :
330332 return '{name}({spec})' .format (
331333 name = self .__class__ .__name__ ,
332334 spec = str (self ),
333335 )
334336
335- def __bool__ (self ):
337+ def __bool__ (self ) -> bool :
336338 return bool (self ._specs )
337339
338- def __lt__ (self , other ) :
340+ def __lt__ (self , other : object ) -> bool :
339341 if not isinstance (other , type (self )):
340342 return False
341343 return str (self ) < str (other )
342344
343- def __eq__ (self , other ) :
345+ def __eq__ (self , other : object ) -> bool :
344346 if not isinstance (other , type (self )):
345347 return False
346348 return str (self ) == str (other )
347349
348- def __hash__ (self ):
350+ def __hash__ (self ) -> int :
349351 return hash (str (self ))
0 commit comments