-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
add inline ignore comment #622
Comments
you can use keep-runtime-typing |
The skip is only needed for the model classes. Other classes or functions would also be skipped with this flag then, right? I would have to give up on annotation upgrades for everything then, which I would like to avoid. I unfortunately forgot while writing the OP that I also (will) have pydantic models outside of the models subpackage, which only holds DB models. The codebase is a fastAPI app. But the issue only occurred with the DB models till now. So even having 2 entries in pre-commit config (One for the model subpackage with the flag and one for the rest without it.) won't cut it unfortunately. |
As a temporary better solution than full ignore I have this now: - repo: https://github.com/asottile/pyupgrade
rev: e695ecd365119ab4e5463f6e49bea5f4b7ca786b # frozen: v2.31.0
hooks:
- id: pyupgrade
name: pyupgrade (not models)
args: ["--py310-plus"]
exclude: .*\/models\/.*
- id: pyupgrade
name: pyupgrade (models)
args: ["--py310-plus", "--keep-runtime-typing"]
files: .*\/models\/.* Which in turn results in:
So the |
show your error? I suspect you're using python<3.9 but you've told pyupgrade you only support python>=3.10 |
but anyway -- this feature request will not be implemented -- there's already the |
The package itself is set to python>=3.10 in its metadata.
What a bummer, would have been nice to skip at individual loc. |
in the future please search the issue tracker -- #574 |
Well the issue was, that I created database models with sqlmodel (bridge between pydantic and sqlalchemy) and then alembic failed the automated database migration. After some further manual testing I found that the issue were some annotations Parallel to this github issue and #623 I further investigated the whole time and found out that it had something to do with In the end I just found the underlying issue, which is already fixed and only needs to be merged: pydantic/pydantic#3681 |
ok so as I suspected, not a pyupgrade bug but a bug in a third party tool -- if you would have led with the actual stacktrace you saw this would have been very obvious and would have saved us all time in the future, please describe your actual problem rather than jumping to prescribing a solution -- I've put together a quick tutorial which outlines a strategy for making bug reports: https://youtu.be/ritp4gAqNMI |
I thought I'd share here for anyone looking for workarounds (not a feature request 😉). I stumbled into the need of an ignore comment today because there's a bug in mypy where it won't work properly with builtin tuple. The workaround is to use A workaround that both works with mypy and prevents pyupgrade from replacing it is to use string syntax with _Shape2D = _HasShape2D | tuple[int, int] | Fraction With this explicit one: _Shape2D: TypeAlias = "_HasShape2D | Tuple[int, int] | Fraction" |
I have a py3.10 code base and run pyupgrade via pre-commit.
In this code base I use pydantic models which use
link to docs
So I have to define a model like this (example from docs):
Which in turn gets modified by pyupgrade:
And this results in a
RuntimeError
from pydantic.To prevent this I currently use the workaround of skiping the model files whole which I luckily have in their own subpackage by ignoring them via the pre-commit config. But skiping them whole is a strong solution and I would rather skip single lines with something like a
# noqa
comment of some sort.The text was updated successfully, but these errors were encountered: