michaelhly / solana-py

Solana Python SDK
https://michaelhly.github.io/solana-py
MIT License
979 stars 252 forks source link

Better typing hints for make_request #447

Closed nhruo123 closed 1 month ago

nhruo123 commented 1 month ago

This closes #446, there are 2 issues I faced during the development processes that made this PR larger then expected.

  1. The project currently supports older version of python (3.7 and above). This was an issue due to the fact that I needed to use the ParamSpec type that was introduced in python 3.10. This forced me to create an untyped version of the function and then two definitions depending on the version of python the user is using. This is not ideal, but I don't see a better solution (beside dropping support for older versions but that's way out of the scope of this PR).
  2. The project is using an outdated version of mypy that didn't support the usage of ParamSpec so I had to bump mypy version to 1.0 and above. This introduced some new mypy errors that I had to fix as well.
nhruo123 commented 1 month ago

I can't make the integration test run on my machine, please let me know if I broke any

michaelhly commented 1 month ago

@nhruo123 are you able to run make lint? Seem like mypy is complaining:

src/solana/rpc/async_api.py:1108: error: Value of type variable "T" of "make_request" of "AsyncHTTPProvider" cannot be "ValidatorExitResp"  [type-var]
src/solana/rpc/api.py:1103: error: Value of type variable "T" of "make_request" of "HTTPProvider" cannot be "ValidatorExitResp"  [type-var]
nhruo123 commented 1 month ago

@nhruo123 are you able to run make lint? Seem like mypy is complaining:

src/solana/rpc/async_api.py:1108: error: Value of type variable "T" of "make_request" of "AsyncHTTPProvider" cannot be "ValidatorExitResp"  [type-var]
src/solana/rpc/api.py:1103: error: Value of type variable "T" of "make_request" of "HTTPProvider" cannot be "ValidatorExitResp"  [type-var]

My bad, I didn't stage that change. Yea, this is a slight issue as ValidatorExitResp is not part of RPCResult (which T is bound to), and we have no control over that type because its in Solders. For now I just added a a comment to ignore typing on the relevant lines, but a long term solution should be to either create our own type over RPCResult and ValidatorExitResp or try to push for a change in Solders.