-
Notifications
You must be signed in to change notification settings - Fork 514
fix: Workaround for JSON value typing problems #581
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
Conversation
|
@janbuchar it solves the first issue i.e. this: request.user_data["item"] = itemHowever the second issue remains: item = context.request.user_data["item"]
item["results"] = context.selector.xpath("normalize-space(//form//strong[1])").get() <-- type error remainsThis is what Pylance reports: Mypy outputs this: When I try to specify a type for the I get this type error from Pylance on the same line: |
This seems correct though -
This way, you say that you expect from typing import cast
# ...
item = cast(dict[str, str | None], context.request.user_data["item"])This way, you tell the type checker that you know what the type is and take full responsibility if you're wrong 🙂 I tried this locally with the relevant part of your code snippet and it seems to work. Did I miss anything? |
No, I think you are perfectly correct ;-) Thanks! |
vdusek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, thanks
user_data#563@tlinhart any chance you could test this and confirm it fixes the issue?