Skip to content

fix Pydantic lax-mode rewrites Pattern[str] to Pattern[LaxStr] and rejects re.Pattern[str] #2991#3001

Closed
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2991
Closed

fix Pydantic lax-mode rewrites Pattern[str] to Pattern[LaxStr] and rejects re.Pattern[str] #2991#3001
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2991

Conversation

@asukaminato0721
Copy link
Copy Markdown
Contributor

Summary

Fixes #2991

Pydantic lax conversion now special-cases regex patterns so re.Pattern[T] expands to re.Pattern[T] | T instead of recursively widening the inner type to LaxStr.

Test Plan

add test

@meta-cla meta-cla Bot added the cla signed label Apr 3, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review April 3, 2026 23:18
Copilot AI review requested due to automatic review settings April 3, 2026 23:18
@github-actions github-actions Bot added the size/s label Apr 3, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Pattern types to produce Pattern[T] | T.
  • Add a regression test asserting correct __init__ signature and acceptance/rejection behavior for re.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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 8, 2026

@stroxler has imported this pull request. If you are a Meta employee, you can view this in D100036927.

Copy link
Copy Markdown
Contributor

@migeed-z migeed-z left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 8, 2026

@stroxler merged this pull request in c12e9d6.

oriori1703 added a commit to oriori1703/sigmatcher that referenced this pull request Apr 12, 2026
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.

Pydantic lax-mode rewrites Pattern[str] to Pattern[LaxStr] and rejects re.Pattern[str]

3 participants