michaelhly / solana-py

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

enhance type hinting for 'connect' to improve IDE support and dev experience #434

Closed circansm closed 3 months ago

circansm commented 3 months ago

Problem: When using connect as demonstrated in the official documentation, IDEs like PyCharm or VSCode incorrectly interpret the type of the returned object as WebSocketClientProtocol instead of SolanaWsClientProtocol. This leads to a lack of autocompletion and type checking for methods like logs_subscribe, which are specific to SolanaWsClientProtocol.

Steps to Reproduce:

  1. Use the connect method in an async context as per the example in the documentation.
  2. Try to call logs_subscribe on the returned object.
  3. Notice that IDEs do not offer autocompletion for logs_subscribe and may show a type warning.

Expected Behavior: The connect method should be clearly typed to return SolanaWsClientProtocol, allowing IDEs to correctly infer the available methods and properties.

Possible Solution: Enhance the type annotations in the connect function to explicitly indicate that it returns an instance of SolanaWsClientProtocol. This could involve adjusting the function's docstring and annotations to provide more explicit guidance to both developers and tools like IDEs.

Additional Context:

michaelhly commented 3 months ago

Happy to accept a PR!

circansm commented 3 months ago

Submitted! Hope I did this correctly =)

michaelhly commented 3 months ago

Completed by #437