fix Pydantic lax-mode rewrites Pattern[str] to Pattern[LaxStr] and rejects re.Pattern[str] #2991#3001
fix Pydantic lax-mode rewrites Pattern[str] to Pattern[LaxStr] and rejects re.Pattern[str] #2991#3001asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Pyrefly’s Pydantic lax-mode type expansion for regex patterns so that re.Pattern[T] (and typing.Pattern[T]) accepts both a compiled pattern and the underlying input type T, without recursively widening T (e.g., avoiding Pattern[LaxStr]).
Changes:
- Add a dedicated lax-mode conversion path for regex
Patterntypes to producePattern[T] | T. - Add a regression test asserting correct
__init__signature and acceptance/rejection behavior forre.Pattern[str]fields.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/alt/class/pydantic_lax.rs |
Special-cases re.Pattern/typing.Pattern during lax expansion to union the pattern type with its type argument. |
pyrefly/lib/test/pydantic/strictness.rs |
Adds a testcase covering re.Pattern[str] lax-mode initialization and rejects bytes input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
@stroxler has imported this pull request. If you are a Meta employee, you can view this in D100036927. |
migeed-z
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
This reverts commit c80b24e. This is no longer needed after facebook/pyrefly#3001
Summary
Fixes #2991
Pydantic lax conversion now special-cases regex patterns so
re.Pattern[T]expands tore.Pattern[T] | Tinstead of recursively widening the inner type to LaxStr.Test Plan
add test