Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "search", "match" and "fullmatch" modes to Regexp validator #871

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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

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.

1 participant