Skip to content

Issue with typeshed's stripe types in stripe.Subscription.delete #770

@YPCrumble

Description

@YPCrumble

First, thank you for maintaining this API wrapper!

Raising this here as this is a commercial library and makes sense for Stripe maintainers to understand the Stripe code better than typeshed maintainers. It also feels like a bug that would make more sense to be fixed here than by making complex type annotations.

The Python typeshed types for this library are raising an issue due to the stripe.Subscription.delete endpoint. Likely in one of these files in typeshed:

https://github.com/python/typeshed/blob/f3ad0179f83699a32a911fe07d3e45e3ac589e5e/stubs/stripe/stripe/api_resources/abstract/deletable_api_resource.pyi

or

https://github.com/python/typeshed/blob/f3ad0179f83699a32a911fe07d3e45e3ac589e5e/stubs/stripe/stripe/util.pyi

or

https://github.com/python/typeshed/blob/f3ad0179f83699a32a911fe07d3e45e3ac589e5e/stubs/stripe/stripe/api_resources/subscription.pyi

Here's the bug:

If I use the following correct code:

stripe.Subscription.delete("sub_1JedlQ2eZvKYlo2Cmc9TYNhw")

this is the error that is raised:

Argument 1 to "delete" has incompatible type "str"; expected "DeletableAPIResource"

I suspect it's due to some of the machinations in the @util.class_method_variant decorator which feels like a code smell - this decorator obfuscates what's happening under the hood to allow a classmethod to be called as either an instance method or as a "classmethod with an instance as the first argument". But why would one want to overload a classmethod like that in the first place?

I suppose an approach would be to fix the type hints somehow in the files I linked above, but likely a better approach would be to remove the @util.class_method_variant in favor of a simpler approach.

It's possible I'm missing the beauty of the decorator; perhaps it's just that I've never seen something that tries to do what it's doing before! In any case, thank you for taking a look at the issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions