⚡ Solution Summary

  • Users unable to reproduce the issue with the same versions of pyright and stripe-python.
  • Ensure correct configuration of Pylance in VSCode.
  • Verify that the correct types are being recognized for stripe.Price.list().
  • Consider updating pyright or checking for conflicting configurations.
### Describe the bug While following the stripe documentation examples I get several type errors with pyright. I read in the documentation the sdk provides precise type annotations but that doesn't seem to be the case for many of the documentation examples. Am I doing something wrong? Is there a solution to this besides muting pyright or writing my own stubs? ### To Reproduce 1. With pyright configured list prices with `prices = stripe.Prices.list()` 2. Accessing `prices.data[0].id` show type error ### Expected behavior No pyright type checking errors ### Code snippets ```Python prices = stripe.Price.list() price_id = prices.data[0].id # <- type error checkout_session = stripe.checkout.Session.create( line_items=[ { 'price': price_id, 'quantity': 1, }, ], mode='subscription', success_url=current_app.config["STRIPE_SUCCESS_REDIRECT_URL"] + '?session_id={CHECKOUT_SESSION_ID}', cancel_url=current_app.config["STRIPE_FAILURE_REDIRECT_URL"], metadata={ "user_id": user_id}, ) checkout_session.url # <- type error ``` ### OS macOS ### Language version Python 3.11.11 ### Library version stripe-python 11.6.0 ### API version 2025-02-24.acacia ### Additional context _No response_

Discussion & Fixes

jar-stripe 2025-03-04
@dmbarreiro Hi! Thanks for the report, and sorry for the trouble! Can you share the error that you're getting, and what version of pyright you are using? I just tried your example code with stripe-python 11.6.0 and pyright 1.1.336 and I am unable to reproduce a type error.
dmbarreiro 2025-03-04
@jar-stripe thank for your swift reply. The pyright version is 1.1.393 used through [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) the vs code python language server using type checking mode standard in pylance config. for `price_id = prices.data[0].id # <- type error` I get these errors: ``` Cannot access attribute "data" for class "list[list[list[Unknown] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]]"   Attribute "data" is unknown ``` ``` Cannot access attribute "data" for class "dict[Unknown, Unknown]"   Attribute "data" is unknown ``` for `checkout_session.url # <- type error` I get these errors: ``` Cannot access attribute "url" for class "list[list[list[Unknown] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]]"   Attribute "url" is unknown ``` ``` Cannot access attribute "url" for class "StripeResponse"   Attribute "url" is unknown ``` ``` Cannot access attribute "url" for class "dict[Unknown, Unknown]"   Attribute "url" is unknown ```
dmbarreiro 2025-03-11
Any success reproducing the problem? Do you need more information?
xavdid-stripe 2025-03-11
I also haven't been able to reproduce this locally (using Pylance through VSCode or pyright directly). I'm using your exact same versions, but all the typechecks are fine for me. When I hover `prices`, I see its type as `prices: ListObject[Price]`, which is expected. `prices.data` is a `List[Price]` and the `.id` property correctly shows: > (variable) `id: str` > Unique identifier for the object. i've also confirmed that missing properties correctly raise pyright issues: <img width="238" alt="Image" src="https://github.com/user-attachments/assets/a4ed7d5e-6fa6-4157-82ab-24663eeadd20" /> This is the same behavior whether i'm going through a `client` instance or `stripe.Price` directly. The `list[list[list[Unknown] | ...` type is definitely an unexpected one. I'd maybe start with that. Do you see the correct types for `stripe.Price` (`(class) Price`) and the `list` method? (`def list(**params: **ListParams) -> ListObject[Price]`)? Do other 3rd party packages work? Does 1st party Python code get checked correctly?
dmbarreiro 2025-03-12
Hello @xavdid-stripe, thanks for you reaction. Answering your questions: 1. I see the correct type for `stripe.Price` which is `(class) Price` 2. For the `stripe.Price.list` method I do not see the correct type, this is what I see ``` (method) def list( api_key: Unknown | None = None, stripe_version: Unknown | None = None, stripe_account: Unknown | None = None, **params: Unknown ) -> (list[list[list[Unknown] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]] | Unknown | Any | StripeResponse | dict[Unknown, Unknown]) ``` 3. Other 3rd party packages work well with our setup and behave as expected regarding the pyright type checking 4. 1st party python code gets checked correctly by pyright
xavdid-stripe 2025-03-12
When you command + click into the `list` definition, does it take you into the Stripe SDK as expected? Either way, the next step is probably to blow away your venv / local dependencies and reinstall everything. It seems like the issue is something specific to your setup.
dmbarreiro 2025-03-13
when I navigate to the stripe.Pricing.list definition I go to `stripe.api_resources.abstract.listable_api_resource.py:ListableAPIResource->list` which is not the right place but it seems like it is specific to my setup and not something you have to fix. Let me know if this last piece of information I provided rings a bell on what could be happening here, otherwise feel free to close the issue. Thank you so much for your support.
xavdid-stripe 2025-03-13
That's the code that powers list methods, but it'd odd that your definition pointed you there. We've inlined the `list` methods onto their respective classes. e.g. jumping to definition for `stripe.Price.list()` takes me to: https://github.com/stripe/stripe-python/blob/bfb694b8329c2bfe0d9d5d1a358d191a93f5311c/stripe/_price.py#L774 `ListableAPIResource` is slated to be removed since it's not needed anymore. That reinforces my thought that the version in your local venv is stale somehow but it's hard to say for sure. Let us know if you figure it out though!

Get updates

We publish verified fixes weekly. No spam.

Subscribe