1717 cast ,
1818)
1919
20+ import os
2021
2122if TYPE_CHECKING :
2223 from typing_extensions import Final
@@ -35,7 +36,7 @@ class SectionWrapper:
3536 config : Final [IniConfig ]
3637 name : Final [str ]
3738
38- def __init__ (self , config : IniConfig , name : str ):
39+ def __init__ (self , config : IniConfig , name : str ) -> None :
3940 self .config = config
4041 self .name = name
4142
@@ -57,7 +58,7 @@ def __iter__(self) -> Iterator[str]:
5758 section : Mapping [str , str ] = self .config .sections .get (self .name , {})
5859
5960 def lineof (key : str ) -> int :
60- return self .config .lineof (self .name , key ) # type: ignore
61+ return self .config .lineof (self .name , key ) # type: ignore[return-value]
6162
6263 yield from sorted (section , key = lineof )
6364
@@ -71,30 +72,35 @@ class IniConfig:
7172 sections : Final [Mapping [str , Mapping [str , str ]]]
7273
7374 def __init__ (
74- self , path : str , data : str | None = None , encoding : str = "utf-8"
75+ self ,
76+ path : str | os .PathLike [str ],
77+ data : str | None = None ,
78+ encoding : str = "utf-8" ,
7579 ) -> None :
76- self .path = str (path ) # convenience
80+ self .path = os . fspath (path )
7781 if data is None :
7882 with open (self .path , encoding = encoding ) as fp :
7983 data = fp .read ()
8084
81- tokens = _parse .parse_lines (path , data .splitlines (True ))
85+ tokens = _parse .parse_lines (self . path , data .splitlines (True ))
8286
8387 self ._sources = {}
8488 sections_data : dict [str , dict [str , str ]]
8589 self .sections = sections_data = {}
8690
8791 for lineno , section , name , value in tokens :
8892 if section is None :
89- raise ParseError (path , lineno , "no section header defined" )
93+ raise ParseError (self . path , lineno , "no section header defined" )
9094 self ._sources [section , name ] = lineno
9195 if name is None :
9296 if section in self .sections :
93- raise ParseError (path , lineno , f"duplicate section { section !r} " )
97+ raise ParseError (
98+ self .path , lineno , f"duplicate section { section !r} "
99+ )
94100 sections_data [section ] = {}
95101 else :
96102 if name in self .sections [section ]:
97- raise ParseError (path , lineno , f"duplicate name { name !r} " )
103+ raise ParseError (self . path , lineno , f"duplicate name { name !r} " )
98104 assert value is not None
99105 sections_data [section ][name ] = value
100106
0 commit comments