weaviate-python-client
weaviate-python-client copied to clipboard
Create stubs for mypy
We should create a stub file so that mypy can lint code that uses this library
Refrences:
Hi @hsm207 I will love to help with this issue. I have already gone ahead and used stubgen to generate a draft. Are we only adding types for the weaviate-python-client/weaviate/ folder?
Hi @EteimZ
cool, thanks for helping with this! Yes weaviate-python-client/weaviate is enough :)
Hi @dirkkul
I forked the typeshed repo and added weaviate stubs to it. Here's the link to it. Can you got through it and tell me if there's any correction to be made before I make a pull request to the typeshed repo.
Hi @EteimZ, sorry that your contribution was left to go stale! We've managed to get the client into a state of mypy compliance so would you be willing to regenerate your stub files with the latest main branch after which I'll give your repository a once over. Following that, you'll be able to open your PR into typesheds and we can get it merged!
Cheers 😁
Sure thing @tsmith023
Hi @tsmith023, Here's the updated stub.
@EteimZ, great news! Thanks for your help on this 😁
I will review once I get the opportunity as we're heavily into a sprint cycle currently!
Okay No Problem @tsmith023
@EteimZ, I believe that the stubs all look fine provided that you called the standard mypy.stubgen command 😁
The only thing that jumps out is that the METADATA.toml seems outdated as the latest package version is v3.24.1. I will run mypy.stubtest on your repo in relation to our main and let you know if it throws any errors!
Alas! I found issues of inconsistency between the stubs and the package due to our misconfiguration of mypy within the pyproject.toml file. I have a PR setup to rectify this, after which we will release a patch with the new package!
@EteimZ, I believe that the stubs all look fine provided that you called the standard
mypy.stubgencommand 😁The only thing that jumps out is that the
METADATA.tomlseems outdated as the latest package version isv3.24.1. I will runmypy.stubteston your repo in relation to ourmainand let you know if it throws any errors!
The stub was generated from version v3.24. I forgot to update the METADATA.toml file.
Alas! I found issues of inconsistency between the stubs and the package due to our misconfiguration of
mypywithin thepyproject.tomlfile. I have a PR setup to rectify this, after which we will release a patch with the new package!
Okay nice, just went through the PR.
@EteimZ, looking at typeshed's CONTRIBUTING.md file here, I think we need to add the stubs used by this library into the requires field. These, as listed in requirements-devel.txt, are:
types-protobuf>=4.24.0.1<5.0.0types-requests>=2.31.0.2<3.0.0types-urllib3>=1.26.25.14<2.0.0
I'm not sure the exact format for how this should be so I'd recommend looking at other libraries in the typeshed repo to see how they format their METADATA.toml files 😁
Here's the requests library as an example
@EteimZ, there's one last thing that needs fixing. A better solution than adding # type: ignore to the auto-generated weaviate_grpc files is to create stubs for this folder. Could you stub it and add your generated stubs to your forked repo of typeshed? I believe once that and the above is done we can open the PR! 😁
@EteimZ, looking at typeshed's
CONTRIBUTING.mdfile here, I think we need to add the stubs used by this library into therequiresfield. These, as listed inrequirements-devel.txt, are:* `types-protobuf>=4.24.0.1<5.0.0` * `types-requests>=2.31.0.2<3.0.0` * `types-urllib3>=1.26.25.14<2.0.0`I'm not sure the exact format for how this should be so I'd recommend looking at other libraries in the typeshed repo to see how they format their
METADATA.tomlfiles 😁Here's the
requestslibrary as an example
Okay @tsmith023 I will update the METADATA.toml.
@EteimZ, there's one last thing that needs fixing. A better solution than adding
# type: ignoreto the auto-generatedweaviate_grpcfiles is to create stubs for this folder. Could you stub it and add your generated stubs to your forked repo of typeshed? I believe once that and the above is done we can open the PR! 😁
The folder structure of the stub repo will be:
- weaviate
- weaviate
- weaviate_grpc
Right?
Hi @tsmith023, I went through the weaviate_grpc folder and I noticed it already contains .pyi stub files. Should I still go on and generate the stubs in my repo?
Yes, I believe the stubs need to be propagated into the typeshed repo in order for them to be available to users when performing mypy static type checking
When you create the stubs for weaviate_grpc you should check whether they are identical to the ones already provided or if there has been a change
In any case, you can perform a sanity check as to whether the stubbing is correct by running mypy.stubtest in comparison between your generated stubs and the weaviate-python-client package itself
Hello, thanks for the great work! Any update on this issue?
Closed by https://github.com/weaviate/weaviate-python-client/pull/1112, sorry for all the delay on this one! Static checking is available in v4.6.5 now 😁