1515if typing .TYPE_CHECKING : # pragma: no cover
1616 from typing import Optional , Union
1717
18+ from mesonpy ._compat import TypedDict
19+
20+ class _AbiDict (TypedDict ):
21+ extension_suffix : str
22+
23+ class _ImplementationVersionDict (TypedDict ):
24+ major : int
25+ minor : int
26+
27+ class _ImplementationDict (TypedDict ):
28+ name : str
29+ version : _ImplementationVersionDict
30+
31+ class BuildDetailsDict (TypedDict ):
32+ abi : _AbiDict
33+ implementation : _ImplementationDict
34+ platform : str
35+
1836
1937# https://peps.python.org/pep-0425/#python-tag
2038INTERPRETERS = {
2947_32_BIT_INTERPRETER = struct .calcsize ('P' ) == 4
3048
3149
32- def get_interpreter_tag (build_details : Optional [dict ] = None ) -> str :
50+ def get_interpreter_tag (build_details : Optional [BuildDetailsDict ] = None ) -> str :
3351 if build_details is None :
3452 name = sys .implementation .name
35- version = sys .version_info
53+ major , minor = sys .version_info [: 2 ]
3654 else :
3755 name = build_details ['implementation' ]['name' ]
3856 _v = build_details ['implementation' ]['version' ]
39- version = (_v ['major' ], _v ['minor' ])
57+ major = _v ['major' ]
58+ minor = _v ['minor' ]
4059 name = INTERPRETERS .get (name , name )
41- return f'{ name } { version [ 0 ] } { version [ 1 ] } '
60+ return f'{ name } { major } { minor } '
4261
4362
4463def _get_config_var (name : str , default : Union [str , int , None ] = None ) -> Union [str , int , None ]:
@@ -58,7 +77,7 @@ def _get_cpython_abi() -> str:
5877 return f'cp{ version [0 ]} { version [1 ]} { debug } { pymalloc } '
5978
6079
61- def get_abi_tag (build_details : Optional [dict ] = None ) -> str :
80+ def get_abi_tag (build_details : Optional [BuildDetailsDict ] = None ) -> str :
6281 if build_details is not None :
6382 ext_suffix = build_details ['abi' ]['extension_suffix' ]
6483 else :
@@ -188,7 +207,7 @@ def _get_ios_platform_tag() -> str:
188207 return f'ios_{ version [0 ]} _{ version [1 ]} _{ multiarch } '
189208
190209
191- def get_platform_tag (build_details : Optional [dict ] = None ) -> str :
210+ def get_platform_tag (build_details : Optional [BuildDetailsDict ] = None ) -> str :
192211 platform = build_details ['platform' ] if build_details is not None else sysconfig .get_platform ()
193212 if platform .startswith ('macosx' ):
194213 return _get_macosx_platform_tag ()
@@ -205,7 +224,7 @@ def get_platform_tag(build_details: Optional[dict] = None) -> str:
205224
206225class Tag :
207226 def __init__ (self , interpreter : Optional [str ] = None , abi : Optional [str ] = None , platform : Optional [str ] = None ,
208- build_details : Optional [dict ] = None ):
227+ build_details : Optional [BuildDetailsDict ] = None ):
209228 self .interpreter = interpreter or get_interpreter_tag (build_details )
210229 self .abi = abi or get_abi_tag (build_details )
211230 self .platform = platform or get_platform_tag (build_details )
0 commit comments