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
Typing issue: CreateParams
for StripeObject
s should allow for Optional values
#1287
Comments
Hi @tetsujiono! Thanks for pointing this out, we'll investigate whether or not to add this for QoL improvement. In the meantime, this is a small improvement: subscription_params : stripe.Subscription.CreateParams = {
"customer": customer_id,
"items": [{"price": price_id}],
"payment_behavior": "error_if_incomplete",
}
if promotion_code:
subscription_params["promotion_code"] = promotion_code
subscription = stripe.Subscription.create(
**subscription_params
) |
BTW, somehow it only complaints when running in ghaction, but not on my Mac with latest mypy and same |
Interesting, for me it's affecting both my local mypy run and the remote mypy workflow step. |
Describe the bug
Many
CreateParams
attributes onStripeObject
s are defined to be non-optional. This means that if that keyword argument is passed into the.create(
function, it must be a non-null value (that also adheres to the defined typing).However, the API supports passing null values on many of these attributes and that seems to contextually make sense.
One example is the promotion_code attribute on the
Subscription
CreateParams
class.The following call succeeds without issue:
however, mypy will find issues with the fact that
promotion_code
isNone
and prefers it not to be passed at all.The workaround at this current moment (other than ignoring the type issue) would be to add a conditional
however, this is quite tedious and becomes unruly if you have more than one attribute you need to check (a permutation of checks will occur)
To Reproduce
error: Argument "promotion_code" to "create" of "Subscription" has incompatible type "str | None"; expected "str" [arg-type]
Expected behavior
Using this line as an example, any nullable
CreateParams
attribute should be noted as OptionalSuggested Solution
^This solution most similarly reflects the way that Optional is implemented on the base
RequestOptions
classCode snippets
OS
macOS
Language version
Python 3.11.3
Library version
stripe-python v8.9.0
API version
2023-10-16
Additional context
No response
The text was updated successfully, but these errors were encountered: