Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1113.
As #1113 reports, the types for our classmethods do not work for MyPy. The problem is our
@class_method_variant
pattern and the fact that we have methods with the same name that double as both class methods and instance methods.MyPy doesn't like it when you do not apply
@classmethod
consistently to all overloads of a method. It complainsI don't mind doing something MyPy doesn't like internally in stripe-python, so long as it gives users types that accurately describe correct usage of the library, but unfortunately in this case MyPy will not generate the overload type that omits
self
orcls
(unlike how Pyright behaves, incidentally). Here's a simplified example:This PR addresses the problem by adding an additional
@staticmethod
overload. This isn't very satisfying, as@staticmethod
is for methods that do not actually need a reference tocls
. On the other hand, because we're only using it on an overload, it doesn't really change the way anything behaves at runtime at all, and it causesMyPy
to generate an overload typed the way we want, i.e.: