KEMBAR78
Add support `re.Pattern[str]` to `pattern` field by jag-k · Pull Request #9053 · pydantic/pydantic · GitHub
Skip to content

Conversation

@jag-k
Copy link
Contributor

@jag-k jag-k commented Mar 19, 2024

Change Summary

I think it just a simple idea about using already compiled regexp to set in pattern field.

Example:

import re

from pydantic import BaseModel, Field

TOKEN_RE = re.compile(r"glpat-.{20}")


class ModelWithToken(BaseModel):
    """Token model with secret."""

    token: SecretStr = Field(pattern=TOKEN_RE)  # Instead of `pattern=TOKEN_RE.pattern`

Related issue number

fix #9052

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable — I don't think we need docs for this
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @davidhewitt

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 19, 2024

CodSpeed Performance Report

Merging #9053 will not alter performance

Comparing jag-k:feat-pattern-as-pattern (6e96b8d) with main (ac9e6ee)

Summary

✅ 10 untouched benchmarks

@jag-k
Copy link
Contributor Author

jag-k commented Mar 19, 2024

please review

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Looks great, would be helpful to add some tests! Thanks!

@pydantic-hooky pydantic-hooky bot added awaiting author revision awaiting changes from the PR author and removed ready for review labels Mar 21, 2024
@pydantic-hooky pydantic-hooky bot assigned jag-k and unassigned davidhewitt Mar 21, 2024
@sydney-runkle
Copy link
Contributor

@jag-k, ping!

@jag-k jag-k requested a review from sydney-runkle March 25, 2024 19:24
@jag-k jag-k force-pushed the feat-pattern-as-pattern branch from ba6a845 to 1e06ec3 Compare March 25, 2024 19:43
@jag-k jag-k force-pushed the feat-pattern-as-pattern branch from 1e06ec3 to 6e96b8d Compare March 25, 2024 19:54
@jag-k
Copy link
Contributor Author

jag-k commented Mar 25, 2024

@jag-k, ping!

@sydney-runkle Sorry to keep you waiting. I missed your message a bit in the mail.

I added tests. Tell me, is everything okay with them?

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for your work on this!

@sydney-runkle sydney-runkle merged commit 00c7815 into pydantic:main Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting author revision awaiting changes from the PR author relnotes-feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support re.Pattern[str] to pattern field in Field

3 participants