jira icon indicating copy to clipboard operation
jira copied to clipboard

Add missing return type hint for resources.py

Open vetleledaal opened this issue 1 year ago • 0 comments

What?

jira/resources.py::Issue::permalink is an untyped function, it should be typed.

Why?

The jira module advertises itself as supporting type hints via py.typed. When used in a typed context and with mypy's strict mode it will complain about the current implementation.

How?

Adding return type hints to jira/resources.py would mitigate the issue.

Testing?

$ cat test.py
from jira.resources import Issue

x = Issue()  # type: ignore
x.permalink()
# Before:
$ mypy --strict test.py | grep '^test\.py'
test.py:4: error: Call to untyped function "permalink" in typed context  [no-untyped-call]
$ _

# After:
$ mypy --strict test.py | grep '^test\.py'
$ _

Has not been tested in runtime. With PEP 563 it is impossible for this PR to break anything under normal conditions. Worst case is that tools used during development show incorrect information, such as an LSP or linter.

Anything Else?

While adding type hints everywhere would be ideal, the PR scope is limited for easier reviewability.

Changes can be summarized as; all methods return None, except for:

  • jira/resources.py::Attachment::get, which returns bytes | None
  • jira/resources.py::Issue::permalink, which returns str

Closes #1900.

vetleledaal avatar Oct 16 '24 19:10 vetleledaal