{"id":1014,"hash":"fd9c890486f7ee2a7ed05f451fc896350bf62a89804a63be59259f99538fb4e7","pattern":"Syntax Error with flake8 and Pydantic Constrained Types: constr(regex=)","full_message":"I use in Python the package pydantic and the linker Flake8. I want to use constr from pydantic with a regular Experssion. Only certain Characters should be passed. (a-z, A-Z, 0-9 and _)\n\nThe regular Experssion \"^[a-zA-Z0-9_]*$\" works, but flake8 shows me the following error:\n\nsyntax error in forward annotation '^[a-zA-Z0-9_]*$' flake8(F722)\n\nclass RedisSettings(BaseModel):\n    keyInput: constr(regex=\"^[a-zA-Z0-9_]*$\") = \"\" \n    keyOutput: constr(regex=\"^[a-zA-Z0-9_]*$\") = \"\"\n\nCan you help me to avoid the Error Message?","ecosystem":"pypi","package_name":"flake8","package_version":null,"solution":"the error here comes from pyflakes which attempts to interpret type annotations as type annotations according to PEP 484\n\nthe annotations used by pydantic are incompatible with PEP 484 and result in that error.  you can read more about this in this pyflakes issue\n\nI'd suggest either (1) finding a way to use pydantic which doesn't involve violating PEP 484 or (2) ignoring the errors from pyflakes using flake8's extend-ignore / # noqa: ... / per-file-ignores\n\ndisclaimer: I am one of the pyflakes maintainers and I am the current flake8 maintainer","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/64909849/syntax-error-with-flake8-and-pydantic-constrained-types-constrregex","votes":18,"created_at":"2026-04-19T04:52:10.777634+00:00","updated_at":"2026-04-19T04:52:10.777634+00:00"}