Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client#search_issues: Incompatible types in assignment (expression has type "Union[str, Issue]", variable has type "Issue") #1608

Closed
2 of 4 tasks
stdedos opened this issue Feb 16, 2023 · 2 comments · Fixed by #1861

Comments

@stdedos
Copy link

stdedos commented Feb 16, 2023

Bug summary

Using

issues = jira.search_issues(query, maxResults=False)

Gives the aforementioned result:

 error: Incompatible types in assignment (expression has type "Union[str, Issue]", variable has type "Issue")  [assignment]

The culprit seems to be:

Returns:
            Union[Dict,ResultList]: Dict if ``json_result=True``

which should be quickly solveable with a little bit of https://mypy.readthedocs.io/en/stable/more_types.html#function-overloading

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.4.1

Python Interpreter version

3.9

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the function with argument x
jira.the_function(x)
# 3.
...

Stack trace

-

Expected behaviour

No typing issues

Additional Context

No response

@GPHemsley-RELX
Copy link

I'm getting a different error in Python 3.11 that I think is caused by the same thing.

If I try to access anything that ResultList has but Dict[str, Any] doesn't, Pylance gets angry.

Cannot access member "total" for type "Dict[str, Any]"
  Member "total" is unknown
Argument of type "Literal[0]" cannot be assigned to parameter "__key" of type "str" in function "__getitem__"
  "Literal[0]" is incompatible with "str"

And if I try say that the return from search_issues is explicitly ResultList during variable assignment, I get this:

Expression of type "Dict[str, Any] | ResultList[Issue]" cannot be assigned to declared type "ResultList[Unknown]"
  Type "Dict[str, Any] | ResultList[Issue]" cannot be assigned to type "ResultList[Unknown]"
    "Dict[str, Any]" is incompatible with "ResultList[Unknown]"

or for ResultList[Issue]:

Expression of type "Dict[str, Any] | ResultList[Issue]" cannot be assigned to declared type "ResultList[Issue]"
  Type "Dict[str, Any] | ResultList[Issue]" cannot be assigned to type "ResultList[Issue]"
    "Dict[str, Any]" is incompatible with "ResultList[Issue]"

So in order to quiet the errors I have to explicitly say:

assert isinstance(issues, jira.client.ResultList)

@Stealthii
Copy link
Contributor

Stealthii commented May 23, 2024

@stdedos @GPHemsley-RELX: #1861 should resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants