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

Introduce stripe.absent_as_none #1229

Closed
wants to merge 4 commits into from

Conversation

richardm-stripe
Copy link
Contributor

@richardm-stripe richardm-stripe commented Feb 8, 2024

Background

Stripe resources have properties that are sometimes absent. The way stripe-python handles this is, it gives you an AttributeError if you try and access the property.

Unfortunately, we type these properties with Optional[...], which implies that you can always access the property but it will sometimes be None.

We can't type the properties with NotRequired[...], as NotRequired only exists for TypedDict and Stripe resources are real classes that extend from StripeObject.

Summary

This PR introduces stripe.absent_as_none. If you set this to true, then stripe-python will give you None when you try and access an absent property, instead of producing an AttributeError. Hypothetical way to address the issue in #1227 without a breaking change.

I'm not sure I like this. I don't know how discoverable we could make stripe.absent_as_none. We could consider adding a message to the AttributeError you get when trying to access an absent property that advertises stripe.absent_as_none, but that would only help a little.

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.

None yet

2 participants