1+ from __future__ import annotations
2+
13import errno
24import math
35import os .path
79import string
810import sys
911from typing import IO
10- from typing import List
11- from typing import Optional
12- from typing import Set
13- from typing import Tuple
1412
1513from identify import extensions
1614from identify import interpreters
3937ALL_TAGS = frozenset (_ALL_TAGS )
4038
4139
42- def tags_from_path (path : str ) -> Set [str ]:
40+ def tags_from_path (path : str ) -> set [str ]:
4341 try :
4442 sr = os .lstat (path )
4543 except (OSError , ValueError ): # same error-handling as `os.lexists()`
@@ -85,7 +83,7 @@ def tags_from_path(path: str) -> Set[str]:
8583 return tags
8684
8785
88- def tags_from_filename (path : str ) -> Set [str ]:
86+ def tags_from_filename (path : str ) -> set [str ]:
8987 _ , filename = os .path .split (path )
9088 _ , ext = os .path .splitext (filename )
9189
@@ -107,7 +105,7 @@ def tags_from_filename(path: str) -> Set[str]:
107105 return ret
108106
109107
110- def tags_from_interpreter (interpreter : str ) -> Set [str ]:
108+ def tags_from_interpreter (interpreter : str ) -> set [str ]:
111109 _ , _ , interpreter = interpreter .rpartition ('/' )
112110
113111 # Try "python3.5.2" => "python3.5" => "python3" until one matches.
@@ -141,7 +139,7 @@ def file_is_text(path: str) -> bool:
141139 return is_text (f )
142140
143141
144- def _shebang_split (line : str ) -> List [str ]:
142+ def _shebang_split (line : str ) -> list [str ]:
145143 try :
146144 # shebangs aren't supposed to be quoted, though some tools such as
147145 # setuptools will write them with quotes so we'll best-guess parse
@@ -155,8 +153,8 @@ def _shebang_split(line: str) -> List[str]:
155153
156154def _parse_nix_shebang (
157155 bytesio : IO [bytes ],
158- cmd : Tuple [str , ...],
159- ) -> Tuple [str , ...]:
156+ cmd : tuple [str , ...],
157+ ) -> tuple [str , ...]:
160158 while bytesio .read (2 ) == b'#!' :
161159 next_line_b = bytesio .readline ()
162160 try :
@@ -177,7 +175,7 @@ def _parse_nix_shebang(
177175 return cmd
178176
179177
180- def parse_shebang (bytesio : IO [bytes ]) -> Tuple [str , ...]:
178+ def parse_shebang (bytesio : IO [bytes ]) -> tuple [str , ...]:
181179 """Parse the shebang from a file opened for reading binary."""
182180 if bytesio .read (2 ) != b'#!' :
183181 return ()
@@ -204,7 +202,7 @@ def parse_shebang(bytesio: IO[bytes]) -> Tuple[str, ...]:
204202 return cmd
205203
206204
207- def parse_shebang_from_file (path : str ) -> Tuple [str , ...]:
205+ def parse_shebang_from_file (path : str ) -> tuple [str , ...]:
208206 """Parse the shebang given a file path."""
209207 if not os .path .lexists (path ):
210208 raise ValueError (f'{ path } does not exist.' )
@@ -231,7 +229,7 @@ def _norm_license(s: str) -> str:
231229 return s .strip ()
232230
233231
234- def license_id (filename : str ) -> Optional [ str ] :
232+ def license_id (filename : str ) -> str | None :
235233 """Return the spdx id for the license contained in `filename`. If no
236234 license is detected, returns `None`.
237235
0 commit comments