Skip to content

Commit f817506

Browse files
committed
Improve Regex display by finding active flags
1 parent 23f4169 commit f817506

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fastjsonschema/generator.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def global_state_code(self):
101101
'',
102102
])
103103
regex_patterns = (
104-
repr(k) + ": " + _repr_regex(v)
104+
repr(k) + ": " + repr_regex(v)
105105
for k, v in self._compile_regexps.items()
106106
)
107107
return '\n'.join(self._extra_imports_lines + [
@@ -298,5 +298,9 @@ def create_variable_is_dict(self):
298298
self.l('{variable}_is_dict = isinstance({variable}, dict)')
299299

300300

301-
def _repr_regex(regex):
302-
return "re.compile({!r}, {!r})".format(regex.pattern, regex.flags)
301+
def repr_regex(regex):
302+
# Unfortunately using `pprint.pformat` is causing errors
303+
all_flags = ("A", "I", "DEBUG", "L", "M", "S", "X")
304+
flags = " | ".join(f"re.{f}" for f in all_flags if regex.flags & getattr(re, f))
305+
flags = ", " + flags if flags else ""
306+
return "re.compile({!r}{})".format(regex.pattern, flags)

0 commit comments

Comments
 (0)