ably-python icon indicating copy to clipboard operation
ably-python copied to clipboard

Add types + Make library PEP-561 compatible

Open Andrioden opened this issue 2 years ago • 5 comments

Why

I love types, and want everything in python typed as strongly as possible within reason. This creates more readable code and makes refactoring easier and safer. If i debug my code that depend on ably code, i find myself stepping into untyped ably code, this makes it harder to read.

The following import triggers an mypy error

game\utils\event_publisher.py

from ably import AblyRest

Running mypy .

game\utils\event_publisher.py:6: error: Skipping analyzing "ably": module is installed, but missing library stubs or py.typed marker  [import]
game\utils\event_publisher.py:6: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

In addition i see the very prominent Channel.publish is not typed.

My suggestions are

  • Make your library PEP-561 compatible
  • Type all public exposed code
  • Add mypy or other type checking to your CI/CD pipelines
  • If possible type the whole repo

Read more here

  • https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
  • https://mypy.readthedocs.io/en/stable/installed_packages.html#installed-packages
  • https://peps.python.org/pep-0561/

┆Issue is synchronized with this Jira Task by Unito

Andrioden avatar Sep 03 '23 16:09 Andrioden

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3842

sync-by-unito[bot] avatar Sep 03 '23 16:09 sync-by-unito[bot]

The "fix" in my repo is to add the following to my config

pyproject.toml

[[tool.mypy.overrides]]
module = "ably.*"
ignore_missing_imports = true

Andrioden avatar Sep 03 '23 16:09 Andrioden

@Andrioden even I agree with you. Typing surely brings more power to the code. In the subsequent iterations, we will surely cover missing types from the code.

sacOO7 avatar Sep 03 '23 16:09 sacOO7

Feel free to raise more suggestions and create a PR if possible : )

sacOO7 avatar Sep 03 '23 16:09 sacOO7

Related to #480

sacOO7 avatar Sep 04 '23 07:09 sacOO7