A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/stripe/stripe-python/wiki/Inline-type-annotations below:

Inline type annotations · stripe/stripe-python Wiki · GitHub

Migration guide: inline type annotations

In stripe-python v7.1.0, we enabled inline type annotations. These annotations describe the shape of the Stripe API much more precisely than the type stubs available in Typeshed, which is good news and bad news.

The good news is that, if you use a type checker like MyPy or Pyright, or a types-enabled IDE, you will now be able to use stripe-python with much more confidence.

The bad news is, when you upgrade to v7.1.0, your type checker may begin to emit more type errors as it begins to validate your integration against the new, more specific types. The inline types supplant the stubs that were available from typeshed, which were very lenient.

If you upgrade to or beyond v7.1.0 and see new errors, there are several possible causes

The easiest way to suppress type errors is with a comment like # type: ignore as demonstrated, but wholesale error suppression is kind of a blunt instrument. If you use the Pyright type checker, you can comment # pyright: ignore[specificDiagnostic] to more specifically suppress any of the particular error categories that pyright features.

If you wish to change some of stripe-python's types to better describe your usage, instead of suppressing them you can override them by writing your own stub .pyi files for stripe-python. (If you use Pyright, you can put them under typings/stripe and they should get picked up by default. If you use MyPy you have to add the path where they are located to the MYPYPATH environment variable, see PEP 561. Writing stubs isn't as easy as writing suppression comments, but it does allow for greater type safety, if your types are accurate.

If you prefer the old, lenient stubs vs. the new inline type annotations, run pip install types-stripe to install the pypi stubs package. This package contains the same stubs that are present in the Typeshed repository, but installing them explicitly as a package will give them a higher precedence than the inline types (see PEP 561). This is only a temporary measure, though. Typeshed stubs are typically removed six months after a package gains inline type annotations.

We release type changes in minor releases. While stripe-python follows semantic versioning, our semantic versions describe the runtime behavior of the library alone. Our type annotations are not reflected in the semantic version. That is, upgrading to a new minor version of stripe-python might result in your type checker producing a type error that it didn't before. You can use a ~=x.x or x.x.* version specifier in your requirements.txt to constrain pip to a certain minor range of stripe-python.

This is similar to the versioning policy we established for our Typescript types, and we are very open to feedback. Please open a Github issue if you have thoughts!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4