-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtypes.py
More file actions
29 lines (19 loc) · 755 Bytes
/
Copy pathtypes.py
File metadata and controls
29 lines (19 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Core type definitions for pattern matching and filtering."""
from __future__ import annotations
import re
from dataclasses import dataclass
from typing import Literal, Union
Pattern = Union[str, re.Pattern[str]]
"""A pattern can be a glob string or a compiled regex."""
MatchTarget = Literal["filename", "path", "path-no-filename", "classname"]
MatchType = Literal["exact", "partial"]
@dataclass(frozen=True)
class PatternMatchingOptions:
"""Options controlling how a pattern is matched against file paths."""
target: MatchTarget = "path"
matching: MatchType = "partial"
@dataclass(frozen=True)
class Filter:
"""A compiled regex filter with matching options."""
regexp: re.Pattern[str]
options: PatternMatchingOptions