Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def __init__(
) -> None:
self._pattern_str: str = pattern_str
flags_list = [
Regex.NAMES[i] for i, f in enumerate(f"{flags:09b}") if f != "0"
Regex.NAMES[i] for i, f in enumerate(f"{int(flags):09b}") if f != "0"
] # Name for each bit

self._flags_names: str = ", flags=" + "|".join(flags_list) if flags_list else ""
Expand Down
13 changes: 13 additions & 0 deletions test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,19 @@ def test_regex():
Regex(None).validate("bar")


def test_regex_flags():
# Passing an actual re flag (a re.RegexFlag enum member, not a plain int)
# must not crash while building the human-readable repr, and the flag must
# still be applied. On CPython <= 3.10 and PyPy, formatting a RegexFlag with
# the "b" format code raised ValueError before the flag was compiled.
single = Regex(r"foo", flags=re.IGNORECASE)
assert single.validate("FOObar") == "FOObar"
assert "re.IGNORECASE" in repr(single)

multi = Regex(r"^foo", flags=re.IGNORECASE | re.MULTILINE)
assert multi.validate("bar\nFOO") == "bar\nFOO"


def test_validate_list():
assert Schema([1, 0]).validate([1, 0, 1, 1]) == [1, 0, 1, 1]
assert Schema([1, 0]).validate([]) == []
Expand Down
Loading