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

Expose regex_engine flag #7768

Merged
merged 1 commit into from Oct 24, 2023
Merged

Conversation

utkini
Copy link
Contributor

@utkini utkini commented Oct 7, 2023

Change Summary

Pydantic-core 2.10.0 added a new flag regex_engine (pydantic/pydantic-core#983).
This flag is provided in Pydantic and documentation has also been added to it.

Related issue number

fix #7714

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
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @adriangb

@utkini utkini marked this pull request as draft October 7, 2023 08:05
@utkini utkini force-pushed the expose-regex-engine branch 4 times, most recently from 80402b7 to aae9c80 Compare October 8, 2023 18:36
@utkini
Copy link
Contributor Author

utkini commented Oct 8, 2023

Hi @davidhewitt
I think I need your knowledge :)
I added a Python example in the documentation for this feature, but the tests don't work.

I tried to dive deeper but still couldn't figure out exactly how to provide it.
I found in pydantic_core.CoreConfig regex_engine in the description, but I didn't found this attribute in the following in the declaration of class fields.
I tied to add line like regex_engine: Literal['rust-regex', 'python-re'] # default: 'rust-regex' but it didn't solve my problem...

I also tried to pass this parameter here
regex_engine=self.config_dict.get('regex_engine'),
but i got another error:

E   pydantic_core._pydantic_core.SchemaError: Invalid Schema:
E   model.config.regex_engine
E     Extra inputs are not permitted [type=extra_forbidden, input_value='python-re', input_type=str]

Could you help me to understand the whole context? :)
Maybe I missing something about how to provide this parameter to CoreConfig

I also tried to do it through the method in core_schema.str_schema,
but I didn't find any relation between str_schema and ConfigDict class in the documentation.

@davidhewitt
Copy link
Contributor

davidhewitt commented Oct 9, 2023

@utkini thanks for flagging, it's an omission in my part in core - I've pushed pydantic/pydantic-core#1011

Once fixed it should be possible to pass regex_engine in the way you attempted, without getting a SchemaError :)

I'll ping here once pydantic main has this fix merged.

@utkini utkini force-pushed the expose-regex-engine branch 4 times, most recently from 31922af to 9ef16f1 Compare October 22, 2023 10:29
@utkini
Copy link
Contributor Author

utkini commented Oct 22, 2023

@davidhewitt I'm ready :)
please review

@utkini utkini marked this pull request as ready for review October 22, 2023 10:48
Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for pushing this over the line!

@davidhewitt davidhewitt merged commit aaf552d into pydantic:main Oct 24, 2023
60 checks passed
@nocturn9x
Copy link

I'm still having a hard time understanding exactly where and how CoreConfig should be used to achieve what I need (and the documentation is of no help at all). Any pointers as to where I should look?

@utkini utkini deleted the expose-regex-engine branch November 5, 2023 16:10
@utkini
Copy link
Contributor Author

utkini commented Nov 5, 2023

Hi @nocturn9x, Could you describe exactly how you want to use this feature?

@nocturn9x
Copy link

nocturn9x commented Nov 5, 2023

Hi there, thanks for replying :)

I think I figured it out (I assume it's the __config__ argument of create_model, which is what I am using, unless that expects a ConfigDict?), but the reason why it wasn't "working" as expected was that I hadn't realized Pydantic 2.5 hadn't been released yet, so the regex_engine flag hadn't been exposed, but if things still don't work after it does release, then I'll definitely come back here to ask for more help :))

@utkini
Copy link
Contributor Author

utkini commented Nov 5, 2023

@nocturn9x, Glad to hear it :)

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

Successfully merging this pull request may close these issues.

Expose regex_engine flag
4 participants