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

Return type incorrect for XMLVerifier.verify when expect_references=1 #257

Open
samueljsb opened this issue Jun 4, 2024 · 3 comments
Open

Comments

@samueljsb
Copy link

The return type for this method is always a union of a single result or a list of results:

# t.py
import signxml

data = object()
result = signxml.XMLVerifier().verify(data, expect_references=1)
reveal_type(result)
$ mypy t.py
t.py:6: note: Revealed type is "Union[signxml.verifier.VerifyResult, builtins.list[signxml.verifier.VerifyResult]]"
Success: no issues found in 1 source file

However, when we only expect one result, we only get one result, so this annotation is unhelpful. Callers shouldn't need to handle the list case.

I believe this can be fixed with typing.overload.

Would a PR be welcome to make that change?

@kislyuk
Copy link
Member

kislyuk commented Jun 4, 2024

Hi, sure, that sounds good. A PR would be welcome.

@samueljsb
Copy link
Author

I've been working from a slightly out of date version and it looks like the expect_references argument has been deprecated and moved to a config object. Given that, I think the only way to make this return type annotation any better would be to make SignatureConfiguration generic on the value of expect_references, which sounds messy.

An up-to-date example of the reproduction:

# t.py
import signxml

data = object()
result = signxml.XMLVerifier().verify(
    data,
    expect_config=signxml.SignatureConfiguration(expect_references=1),
)
reveal_type(result)
$ mypy t.py
t.py:9: note: Revealed type is "Union[signxml.verifier.VerifyResult, builtins.list[signxml.verifier.VerifyResult]]"
Success: no issues found in 1 source file

@samueljsb
Copy link
Author

I can't seem to make this work with generics and overloads, so this might not be solvable through mypy at the moment. 😕

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

No branches or pull requests

2 participants