summaryrefslogtreecommitdiff
path: root/tools/lib/python
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+huawei@kernel.org>2026-03-02 17:40:54 +0100
committerJonathan Corbet <corbet@lwn.net>2026-03-03 10:47:25 -0700
commit95a9429cc6d31371575793ab7beb94bf3e7a2f92 (patch)
tree591895470f4eadefab5d2fb8c34ad296f2e0d78e /tools/lib/python
parent97d4e70bc2c6f75911a9a5e1a75f2de13fde9b6b (diff)
docs: kdoc_re: better show KernRe() at documentation
the __repr__() function is used by autodoc to document macro initialization. Add a better representation for them. Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net> Message-ID: <80d27732368c14125c1b76048a70d8b4aee527ef.1772469446.git.mchehab+huawei@kernel.org>
Diffstat (limited to 'tools/lib/python')
-rw-r--r--tools/lib/python/kdoc/kdoc_re.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/lib/python/kdoc/kdoc_re.py b/tools/lib/python/kdoc/kdoc_re.py
index 6c44fcce0415..664c04c8cc9f 100644
--- a/tools/lib/python/kdoc/kdoc_re.py
+++ b/tools/lib/python/kdoc/kdoc_re.py
@@ -52,7 +52,28 @@ class KernRe:
return self.regex.pattern
def __repr__(self):
- return f're.compile("{self.regex.pattern}")'
+ """
+ Returns a displayable version of the class init.
+ """
+
+ flag_map = {
+ re.IGNORECASE: "re.I",
+ re.MULTILINE: "re.M",
+ re.DOTALL: "re.S",
+ re.VERBOSE: "re.X",
+ }
+
+ flags = []
+ for flag, name in flag_map.items():
+ if self.regex.flags & flag:
+ flags.append(name)
+
+ flags_name = " | ".join(flags)
+
+ if flags_name:
+ return f'KernRe("{self.regex.pattern}", {flags_name})'
+ else:
+ return f'KernRe("{self.regex.pattern}")'
def __add__(self, other):
"""