11import re
2- from abc import ABCMeta
2+ from abc import ABCMeta , abstractmethod
33from typing import Iterator , Mapping , Optional , Pattern
44
5- _posix_variable = re .compile (
5+ _posix_variable : Pattern [ str ] = re .compile (
66 r"""
77 \$\{
88 (?P<name>[^\}:]*)
1212 \}
1313 """ ,
1414 re .VERBOSE ,
15- ) # type: Pattern[str]
15+ )
1616
1717
18- class Atom ():
19- __metaclass__ = ABCMeta
20-
18+ class Atom (metaclass = ABCMeta ):
2119 def __ne__ (self , other : object ) -> bool :
2220 result = self .__eq__ (other )
2321 if result is NotImplemented :
2422 return NotImplemented
2523 return not result
2624
27- def resolve ( self , env : Mapping [ str , Optional [ str ]]) -> str :
28- raise NotImplementedError
25+ @ abstractmethod
26+ def resolve ( self , env : Mapping [ str , Optional [ str ]]) -> str : ...
2927
3028
3129class Literal (Atom ):
3230 def __init__ (self , value : str ) -> None :
3331 self .value = value
3432
3533 def __repr__ (self ) -> str :
36- return "Literal(value={})" . format ( self .value )
34+ return f "Literal(value={ self .value } )"
3735
3836 def __eq__ (self , other : object ) -> bool :
3937 if not isinstance (other , self .__class__ ):
@@ -53,7 +51,7 @@ def __init__(self, name: str, default: Optional[str]) -> None:
5351 self .default = default
5452
5553 def __repr__ (self ) -> str :
56- return "Variable(name={}, default={})" . format ( self .name , self . default )
54+ return f "Variable(name={ self . name } , default={ self .default } )"
5755
5856 def __eq__ (self , other : object ) -> bool :
5957 if not isinstance (other , self .__class__ ):
@@ -74,8 +72,8 @@ def parse_variables(value: str) -> Iterator[Atom]:
7472
7573 for match in _posix_variable .finditer (value ):
7674 (start , end ) = match .span ()
77- name = match . groupdict () ["name" ]
78- default = match . groupdict () ["default" ]
75+ name = match ["name" ]
76+ default = match ["default" ]
7977
8078 if start > cursor :
8179 yield Literal (value = value [cursor :start ])
0 commit comments