Skip to content

Fix peewee issues with pyright when updating a CharField and then saving it #200

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

Open
benoit74 opened this issue Aug 18, 2023 · 9 comments
Milestone

Comments

@benoit74
Copy link
Collaborator

When updating an ORM object (e.g. book.html_etag = etag), #191 had to add # type: ignore hint because pyright was complaining that a str cannot be used to set a CharField

This is clearly a peewee issue, maybe linked to the fact that we are using an old version.

To be fixed / reported upstream if not already fixed.

@benoit74 benoit74 added this to the 2.2.0 milestone Aug 18, 2023
@benoit74 benoit74 modified the milestones: 2.2.0, 2.3.0 Mar 28, 2025
@Lorrainnn
Copy link
Contributor

I came across the same issue and checked Peewee’s GitHub — it looks like there’s no existing issue about this.
Do you think it’s still worth reporting upstream, or would it make sense for me to try submitting a fix?
Also, would using cast(str | None, CharField(...)) be a better workaround than # type: ignore?

This is question somehow very similar to issue #201 .

@benoit74
Copy link
Collaborator Author

Asking for help upstream is indeed a good idea, please do, thanks.

@Lorrainnn
Copy link
Contributor

Reported to upstream: coleifer/peewee#2980

@benoit74
Copy link
Collaborator Author

benoit74 commented Apr 1, 2025

Maybe worth to give a try to https://pypi.org/project/types-peewee/

@Lorrainnn
Copy link
Contributor

Maybe worth to give a try to https://pypi.org/project/types-peewee/

lol This one works. I am testing on it rn.

@Lorrainnn
Copy link
Contributor

I'm not sure why, but this solution seems a bit unstable. I'm currently looking for more type stubs for Peewee, so any suggestions are welcome! :)

@benoit74
Copy link
Collaborator Author

benoit74 commented Apr 4, 2025

this solution seems a bit unstable.

what kind of instability?

@Lorrainnn
Copy link
Contributor

Lorrainnn commented Apr 5, 2025

Yeah, I just meant that Pyright was picking up the types-peewee stubs before, (literally after 1 night, but now it’s not lmao. Not sure why rn

Update 4/5: Ok. So I double-checked types-peewee. It works as

[tool.pyright]
include = ["src", "tests", "tasks.py"]
exclude = ["**/node_modules", "**/__pycache__", "src/gutenberg2zim/templates"]
extraPaths = ["src", "/root/.local/share/hatch/env/virtual/gutenberg2zim/TINSWTDS/gutenberg2zim/lib/python3.13/site-packages"]

but isn't hatch would automatically find this libs. Kinda confused at this point. And the update would generates 2 extra error as

line40: return r.status_code == requests.codes.ok

download.py:40:48 - error: Cannot access attribute "ok" for class "LookupDict"
    Attribute "ok" is unknown (reportAttributeAccessIssue)

@benoit74
Copy link
Collaborator Author

benoit74 commented Apr 7, 2025

I will have a look later, probably not in the coming days however, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants