You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When checking Pydantic models in Pyrefly, constructor parameters for re.Pattern[str] fields appear to be rewritten as Pattern[LaxStr] in lax mode.
This then causes valid re.Pattern[str] values (from re.compile(...)) to be rejected by static checking.
This seems inconsistent with runtime Pydantic behavior and likely indicates a bug/edge case in lax-type conversion for re.Pattern[...].
ERROR Argument `Pattern[str]` is not assignable to parameter `signature` with type `Pattern[LaxStr]` in function `RegexSignature.__init__` [bad-argument-type]
(From my project this occurs in many callsites with the same shape.)
Expected behavior
No type error for re.compile(...) when field type is re.Pattern[str].
Actual behavior
Pyrefly reports Pattern[str] is not assignable to Pattern[LaxStr].
Runtime Pydantic does not accept bytes for this field (e.g. signature=b"x" fails validation), so expanding to LaxStr may be over-broad for Pattern[str].
pyright and mypy report no errors on the same callsites.
Potentially, re.Pattern[T] may need special handling instead of recursively applying str -> LaxStr inside the type parameter.
Important
Although I encountered and debugged the issue myself, I used AI to create the content of the issue. I then verified the content of the issue and checked that the reproduction is correct.
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
Describe the Bug
Summary
When checking Pydantic models in Pyrefly, constructor parameters for
re.Pattern[str]fields appear to be rewritten asPattern[LaxStr]in lax mode.This then causes valid
re.Pattern[str]values (fromre.compile(...)) to be rejected by static checking.This seems inconsistent with runtime Pydantic behavior and likely indicates a bug/edge case in lax-type conversion for
re.Pattern[...].Minimal repro
Pyrefly output
(From my project this occurs in many callsites with the same shape.)
Expected behavior
No type error for
re.compile(...)when field type isre.Pattern[str].Actual behavior
Pyrefly reports
Pattern[str]is not assignable toPattern[LaxStr].Why this looks wrong
RegexSignature(signature=re.compile("x"))RegexSignature(signature="x")(string pattern coercion)signature=b"x"fails validation), so expanding toLaxStrmay be over-broad forPattern[str].pyrightandmypyreport no errors on the same callsites.Environment
pyrefly 0.59.0pydantic 2.12.5Python 3.14.3Additional context
This appears related to Pyrefly’s Pydantic lax-mode conversion behavior:
https://pyrefly.org/en/docs/pydantic/#how-lax-mode-works-in-pyrefly
Potentially,
re.Pattern[T]may need special handling instead of recursively applyingstr -> LaxStrinside the type parameter.Important
Although I encountered and debugged the issue myself, I used AI to create the content of the issue. I then verified the content of the issue and checked that the reproduction is correct.
Sandbox Link
No response
(Only applicable for extension issues) IDE Information
No response