Skip to content

Conversation

@artempronevskiy
Copy link

Description:

Currently Regexp validator supports only re.match mode, but sometimes we need to use re.fullmatch or re.search mode.

Relevant issues or pull requests:

#867

What this PR does to fix the issue:

  • Added support of re.fullmatch and re.search modes along with re.match with full backward compatibility
  • Introduced new ValidatorSetupError exception to be raised if an user is trying to set up validator in a wrong way
  • Added additional tests for Regexp validator to cover the changes
  • Updated docs/fields.rst file to show added mode kwarg to Regexp.__init__()

@artempronevskiy artempronevskiy force-pushed the add-fullmatch-support-to-regexp-validator branch 2 times, most recently from 9ab5825 to 8fdd991 Compare November 22, 2024 12:50
@artempronevskiy artempronevskiy force-pushed the add-fullmatch-support-to-regexp-validator branch from fe1584d to 0c355e6 Compare November 22, 2024 12:52
Comment on lines +360 to +361
def __init__(self, regex, flags=0, message=None, mode="match"):
self.mode = self._validate_mode(mode)
Copy link
Author

@artempronevskiy artempronevskiy Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my POV it's better to validate mode value in __init__() in order to prevent the object instantiating with invalid data. in other words, validating mode value is a check of the invariant (mode field has supported value) and thus the object must not be created/instantiated if any of invariant checks failed.

@dougthor42
Copy link

dougthor42 commented Jul 18, 2025

/poke reviewers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants