Skip to content

Annotate braintree's MultipleValueNodeBuilder.in_list method - #16235

Merged
srittau merged 4 commits into
python:mainfrom
cuu508:annotate_braintree_in_list
Aug 20, 2026
Merged

Annotate braintree's MultipleValueNodeBuilder.in_list method#16235
srittau merged 4 commits into
python:mainfrom
cuu508:annotate_braintree_in_list

Conversation

@cuu508

@cuu508 cuu508 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This adds type annotations for braintree.search.Search.MultipleValueNodeBuilder.in_list.

Looking at the source, the return value can only be Search.Node.

It's less clear what the type of *values elements can be, but grepping around the source it looked like it's only str.

@github-actions

This comment has been minimized.

@donbarbos donbarbos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Just one nit

whitelist: Incomplete
def __init__(self, name, whitelist=[]) -> None: ...
def in_list(self, *values): ...
def in_list(self, *values: str) -> Search.Node: ...

@donbarbos donbarbos Aug 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a list can be used as such a sequence of values for the first argument, I think it might be worth adding an overload for this case.
(Please, import Unused from _typeshed)

Suggested change
def in_list(self, *values: str) -> Search.Node: ...
@overload
def in_list(self, value: list[str], *values: Unused) -> Search.Node: ...
@overload
def in_list(self, *values: str) -> Search.Node: ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donbarbos oops, missed that. Thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with braintree, but I assume calling in_list if a list as first argument and further arguments would indicate a bug or misunderstanding of the API. In this case I think it's safer to remove the *values argument from the first overload.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if the first argument is a list, it uses it and ignores the rest:

        def in_list(self, *values):
            if isinstance(values[0], list):
                values = values[0]

Passing a list and anything following it would not throw an error, but also would not make any sense. I removed the *values: Unused bit from the PR.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit 35d6ae5 into python:main Aug 20, 2026
74 checks passed
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 this pull request may close these issues.

3 participants