Coverage for packages/pyswig/src/pyswig/types.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-06-26 21:05 +0000

1# Copyright (c) 2015-2020 Michel Gillet 

2# SPDX-License-Identifier: MIT 

3 

4from __future__ import annotations 

5 

6from typing import NamedTuple, Union 

7 

8 

9class TagRecord(NamedTuple): 

10 """Tags metadata parsed from one annotated header.""" 

11 

12 file: str | None 

13 tags: list[str] | None 

14 

15 

16class DefineRecord(NamedTuple): 

17 """Preprocessor define written into the main Swig interface file.""" 

18 

19 name: str 

20 value: str | None 

21 

22 

23class ReplaceStringPair(NamedTuple): 

24 """Search/replace pair applied to Swig-generated wrapper sources.""" 

25 

26 orig: str 

27 new: str 

28 

29 

30class SourceFileSpec(NamedTuple): 

31 """Normalized source header entry from a FileConfig source list.""" 

32 

33 name: str 

34 wrap: bool = False 

35 

36 

37SourceFileEntry = Union[str, list[Union[str, bool]]] 

38 

39 

40def normalize_source_entry(entry: SourceFileEntry) -> SourceFileSpec: 

41 """Normalize legacy source list entries to a SourceFileSpec.""" 

42 if isinstance(entry, list): 

43 return SourceFileSpec(str(entry[0]), bool(entry[1])) 

44 return SourceFileSpec(str(entry))