Coverage for src/debputy/lsprotocol/types.py: 23%
27 statements
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2025-01-27 13:59 +0000
1"""Wrapper module around `lsprotocol.types`
3This wrapper module is here to facility making `lsprotocol` optional
4for -backports. When available, it is a (mostly) transparent wrapper
5for the real module. When missing, it returns a placeholder object
6for anything for the purpose of making things simpler.
7"""
9from typing import TYPE_CHECKING, Any, Iterator, List
11if TYPE_CHECKING:
12 from lsprotocol import types
14 # To defeat "unused" detections that might attempt to
15 # optimize out the import
16 assert types is not None
17 __all__ = dir(types)
19else:
20 try:
21 from lsprotocol import types
23 __all__ = dir(types)
25 except ImportError:
27 stub_attr = {
28 "__name__": __name__,
29 "__file__": __file__,
30 "__doc__": __doc__,
31 }
32 bad_attr = frozenset(
33 [
34 "pytestmark",
35 "pytest_plugins",
36 ]
37 )
39 class StubModule:
40 @staticmethod
41 def __getattr__(item: Any) -> Any:
42 if item in stub_attr:
43 return stub_attr[item]
44 if item in bad_attr:
45 raise AttributeError(item)
46 if isinstance(item, str) and item.startswith("TEXT_"):
47 return str(item)
48 return types
50 def __call__(self, *args, **kwargs) -> Any:
51 return self
53 def __iter__(self) -> Iterator[Any]:
54 return iter(())
56 types = StubModule()
57 __all__ = []
60def __dir__() -> List[str]:
61 return dir(types)
64def __getattr__(name: str) -> Any:
65 return getattr(types, name)