Coverage for src/pytkdocs/properties.py: 100.00%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""This module simply defines regular expressions and their associated predicates."""
3import re
4from typing import Callable, Pattern, Tuple
6ApplicableNameProperty = Tuple[str, Callable[[str], bool]]
8# exactly two leading underscores, exactly two trailing underscores
9# since we enforce one non-underscore after the two leading underscores,
10# we put the rest in an optional group
11RE_SPECIAL: Pattern = re.compile(r"^__[^_]([\w_]*[^_])?__$")
12"""Regular expression to match `__special__` names."""
14# at least two leading underscores, at most one trailing underscore
15# since we enforce one non-underscore before the last,
16# we make the previous characters optional with an asterisk
17RE_CLASS_PRIVATE: Pattern = re.compile(r"^__[\w_]*[^_]_?$")
18"""Regular expression to match `__class_private` names."""
20# at most one leading underscore, then whatever
21RE_PRIVATE: Pattern = re.compile(r"^_[^_][\w_]*$")
22"""Regular expression to match `_private` names."""
24NAME_SPECIAL: ApplicableNameProperty = ("special", lambda name: bool(RE_SPECIAL.match(name)))
25"""Applicable property: `special`."""
27NAME_CLASS_PRIVATE: ApplicableNameProperty = ("class-private", lambda name: bool(RE_CLASS_PRIVATE.match(name)))
28"""Applicable property: `class-private`."""
30NAME_PRIVATE: ApplicableNameProperty = ("private", lambda name: bool(RE_PRIVATE.match(name)))
31"""Applicable property: `private`."""