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

15 statements  

1"""This module simply defines regular expressions and their associated predicates.""" 

2 

3import re 

4from typing import Callable, Pattern, Tuple 

5 

6ApplicableNameProperty = Tuple[str, Callable[[str], bool]] 

7 

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.""" 

13 

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.""" 

19 

20# at most one leading underscore, then whatever 

21RE_PRIVATE: Pattern = re.compile(r"^_[^_][\w_]*$") 

22"""Regular expression to match `_private` names.""" 

23 

24NAME_SPECIAL: ApplicableNameProperty = ("special", lambda name: bool(RE_SPECIAL.match(name))) 

25"""Applicable property: `special`.""" 

26 

27NAME_CLASS_PRIVATE: ApplicableNameProperty = ("class-private", lambda name: bool(RE_CLASS_PRIVATE.match(name))) 

28"""Applicable property: `class-private`.""" 

29 

30NAME_PRIVATE: ApplicableNameProperty = ("private", lambda name: bool(RE_PRIVATE.match(name))) 

31"""Applicable property: `private`."""