Skip to content

braintree: Replace usages of Any #11679

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

Merged
merged 5 commits into from
Apr 1, 2024
Merged

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Mar 31, 2024

Based on #11678 so please merge that first
Works towards #9550 .

The biggest point of interest in this PR, is how braintree does its dynamic values. Any subclass of AttributeGetter expect a attributes dict that is used to create all the fields. This means, however, that whilst some fields are never indicated as being potentially None, they could still raise AttributeError if missing or optional from the initial attributes.

This also means that if an attribute is to be used as-is without any special manipulation, then it will be missed by stugben and stubtest.
I've added a relevant comment in stubs/braintree/braintree/attribute_getter.pyi

This comment has been minimized.

Comment on lines 41 to 54
payment_methods: list[
CreditCard
| Address
| PayPalAccount
| ApplePayCard
| AndroidPayCard
| AmexExpressCheckoutCard
| EuropeBankAccount
| VenmoAccount
| UsBankAccount
| VisaCheckoutCard
| MasterpassCard
| SamsungPayCard
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
payment_methods: list[
CreditCard
| Address
| PayPalAccount
| ApplePayCard
| AndroidPayCard
| AmexExpressCheckoutCard
| EuropeBankAccount
| VenmoAccount
| UsBankAccount
| VisaCheckoutCard
| MasterpassCard
| SamsungPayCard
]
payment_methods: list[Resource]

Since you'd have to use isinstance anyway for most usage, and indidual types are already available in their own separate lists, it makes sense to simplify this definition

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Apr 1, 2024

Conflicts now (as expected).

Copy link
Contributor

github-actions bot commented Apr 1, 2024

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

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Looks sensible.

@srittau srittau merged commit 48d0234 into python:main Apr 1, 2024
43 checks passed
@Avasam Avasam deleted the braintree-no-any branch April 1, 2024 14:36
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.

2 participants