Coverage for typed_stream/_impl/_typing.py: 85%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-12 21:24 +0000

1# Licensed under the EUPL-1.2 or later. 

2# You may obtain a copy of the licence in all the official languages of the 

3# European Union at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12 

4 

5"""Provide types.""" 

6 

7from __future__ import annotations 

8 

9import typing 

10 

11if typing.TYPE_CHECKING: # noqa: C901 # pragma: no cover 

12 import sys 

13 

14 if sys.version_info < (3, 11): 

15 from typing_extensions import ( 

16 Self, 

17 TypeVarTuple, 

18 Unpack, 

19 assert_never, 

20 assert_type, 

21 ) 

22 else: 

23 from typing import Self, TypeVarTuple, Unpack, assert_never, assert_type 

24 

25 if sys.version_info < (3, 12): 

26 from typing_extensions import override 

27 else: 

28 from typing import override 

29else: 

30 

31 def return_arg(arg: object, *_) -> object: 

32 """Return the argument.""" 

33 return arg 

34 

35 def assert_never(arg: object, /) -> typing.Never: 

36 """Never call this.""" 

37 raise AssertionError(f"{arg} was not never") 

38 

39 Self = getattr(typing, "Self", ...) 

40 TypeVarTuple = getattr(typing, "TypeVarTuple", return_arg) 

41 Unpack = getattr(typing, "Unpack", ...) 

42 override = getattr(typing, "override", return_arg) 

43 assert_type = getattr(typing, "assert_type", return_arg) 

44 assert_never = getattr(typing, "assert_never", assert_never) 

45 

46__all__ = ( 

47 "Self", 

48 "TypeVarTuple", 

49 "Unpack", 

50 "override", 

51 "assert_type", 

52 "assert_never", 

53)