Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pathspec/backend.py: 91%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

11 statements  

1""" 

2This module defines the necessary classes and type hints for exposing the bare 

3minimum of the internal implementations for the pattern (regular expression) 

4matching backends. The exact structure of the backends is not solidified and is 

5subject to change. 

6""" 

7 

8from collections.abc import ( 

9 Sequence) 

10from typing import ( 

11 Callable, # Replaced by `collections.abc.Callable` in 3.9.2. 

12 Literal, 

13 Optional) # Replaced by `X | None` in 3.10. 

14 

15from .pattern import ( 

16 Pattern) 

17 

18BackendNamesHint = Literal['best', 'hyperscan', 're2', 'simple'] 

19""" 

20The supported backend values. 

21""" 

22 

23_TestBackendFactoryHint = Optional[Callable[[Sequence[Pattern]], '_Backend']] 

24""" 

25Type hint for the test backend factory argument. 

26""" 

27 

28 

29class _Backend(object): 

30 """ 

31 .. warning:: This class is not part of the public API. It is subject to 

32 change. 

33 

34 The :class:`_Backend` class is the abstract base class defining how to match 

35 files against patterns. 

36 """ 

37 

38 def match_file(self, file: str) -> tuple[Optional[bool], Optional[int]]: 

39 """ 

40 Check the file against the patterns. 

41 

42 *file* (:class:`str`) is the normalized file path to check. 

43 

44 Returns a :class:`tuple` containing whether to include *file* (:class:`bool` 

45 or :data:`None`), and the index of the last matched pattern (:class:`int` or 

46 :data:`None`). 

47 """ 

48 raise NotImplementedError(( 

49 f"{self.__class__.__module__}.{self.__class__.__qualname__}.match_file() " 

50 f"must be implemented." 

51 )) # NotImplementedError