-
-
Notifications
You must be signed in to change notification settings - Fork 14
[REQ][python] get user's mypy check passing with warn_redundant_casts turned on #246
Comments
Can you please provide your openapi document and the 30 errors? Mypy is successfully passing on the petstore sample in CI. |
The OpenAPI is here. |
What are the 30 errors you get on your project? I only get 6.
-->
|
@nponsard my merged PR should resolve this issue. Can you please verify that? |
I still have some errors :
It's weird that you don't have these ones reported. |
Please provide the steps to reproduce your output.
|
Here's what I've done
|
This is happening because you have:
turned on in your pyproject.toml which is defaulted to false if unset |
@nponsard I just merged in a commit that should eliminate your redundant casts issue. Can you verify it on your side? Locally it eliminated all redundant casts issues when mypy was run against the petstore client with warn_redundant_casts turned on. |
@spacether Thanks for the fix! To provide some context on why we set Ideally, the OpenAPI generated code would also pass strict checks, but passing Now back to this issue: I’ve re-generated the code with the latest Docker image (
Unfortunately it looks like the changes cause a different problem. Consider this snippet from response = self.get_api().users_get()
return [str(item["user"]) for item in response.body]
|
You're welcome for the two PRs. I can't tell what the root cause is from the trace that you posted. Does your repo include the latest update? It does not look like it does. Can you please post a repo or branch that demonstrates the current problems that I can look at? I have not run into similar problems. |
Based on the additional context that you provided, you are expected strict mode options to pass when running mypy. mypy strict mode checks are not yet working on the client. When one runs mypy with the default options, not the additional ones that you specify in your toml file, it passed. Because of this, I am changing this to a feature request to get mypy passing with the warn_redundant_casts turned on. |
I’ve created a draft PR with the updated client code that causes both the |
Thanks, I am also working on this in: spacether/nethsm-sdk-py#1 but I am running into issues where the ApiResponse.body types are not correctly seen by mypy. I am seeing errors like:
|
I think this is the same problem that I mentioned here (in the last paragraph). Here’s the full list of errors that I get with our setup: https://github.com/Nitrokey/nethsm-sdk-py/actions/runs/6499415750/job/17652723428?pr=42 |
So I just converted the ApiResponse classes back to dataclasses and removed default values in all except ApiResponseWithoutDeserialization. Then I rebuilt your client with it here:
Please verify that my new code solves your mypy issues. I have not been able to replicate your lingering redundant_cast issues though I see in time_config.py TimeConfigDict.time that there is a redundant cast happening. |
I’ve updated the draft PR Nitrokey/nethsm-sdk-py#42 using d2d1d8b. The request body issues are now fixed, but I still get the redundant cast warnings:
I’m using Python 3.9.2 and mypy 1.6.0. It also fails in the CI, so it is not limited to my environment: https://github.com/Nitrokey/nethsm-sdk-py/actions/runs/6507023981/job/17673671662. And it also happens with Python 3.10.13: https://github.com/Nitrokey/nethsm-sdk-py/actions/runs/6507070669/job/17673794274 What mypy version do you use? What happens if you run mypy on my branch? |
Until upstream issue #246 [0] is fixed, pinning openapi-json-schme-generator-cli to 3.1.0 makes sure that the CI pases and that the generated code works with our existing code. [0] openapi-json-schema-tools/openapi-json-schema-generator#246
So I grabbed your branch and ran it locally. In it, I needed to pin to python 3.9 because my system default python is 3.8.
My python is:
Any my mypy is: 1.6.0 However your branch is anchored on my 3.1.0 release so it will always have that issue. I am not understanding why my new branch is not generating the redundant casts issue:
Can you please please pull my branch |
For the Nitrokey/nethsm-sdk-py#42 branch, I built the Docker image locally from Git (d2d1d8b) and re-generated the client code so it was up to date and not from 3.1.0. Your branch on spacether/nethsm-sdk-py@ea8e891 still has
I’ve updated my Nitrokey/nethsm-sdk-py#42 branch using 24c9e46 and I think all issues are fixed now. 🎉 Edit: CI agrees! |
Glad to hear it. I will add some tests to #252 before I merge it in. Happy to hear that it solved your issues. |
@robin-nitrokey today I released v3.1.1 which includes the fixes needed by this issue. Please use it to resolve this warn_redundant_casts mypy issue. Thank you for reporting this issue and providing more info and context on the causes. |
@spacether Great! Thank you for working on this issue and for publishing the fix! I’ve update my PR to use the released version. Nitrokey/nethsm-sdk-py#42 |
You're welcome 🙂 |
I’ve now enabled strict checks for our own code and it works nicely with the generated code. :) Only one small issue remains: |
Feel free to submit PRs to the generator to fix any issues that you find. Contributions are welcome. |
Is your feature request related to a problem? Please describe.
I tried to run mypy on code generated by this project and got around 30 errors. The same happens when running mypy on the provided samples. There was an issue about that one year ago #1, is this a regression ?
Some errors I get on my project :
Describe the solution you'd like
That the generated code doesn't emit any type error with
mypy
.Describe alternatives you've considered
I disabled type checking for the folder containing the generated code in my pyproject.toml :
The text was updated successfully, but these errors were encountered: