Repository navigation
feat: Add py.typed marker and fix type annotations - #180
Merged
Merged
Conversation
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 14:31 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 14:31 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 14:31 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 14:31 — with
GitHub Actions
Inactive
davidgrayston-paddle
marked this pull request as ready for review
November 18, 2026 14:44
davidgrayston-paddle
marked this pull request as draft
November 18, 2026 15:10
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:14 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:14 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:14 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:14 — with
GitHub Actions
Inactive
davidgrayston-paddle
force-pushed
the
fix/py-typed
branch
from
November 18, 2026 15:15
eefc2d8 to
67440ce
Compare
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:15 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:15 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:15 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 15:15 — with
GitHub Actions
Inactive
davidgrayston-paddle
marked this pull request as ready for review
November 18, 2026 15:35
davidgrayston-paddle
marked this pull request as draft
November 18, 2026 15:37
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:04 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:04 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:04 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:04 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:38 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:38 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:38 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 16:38 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 19:12 — with
GitHub Actions
Inactive
davidgrayston-paddle
temporarily deployed
to
dev
November 18, 2026 19:12 — with
GitHub Actions
Inactive
Request became a Union alias, so subclassing it raised TypeError. Keep Request as a protocol with headers, extend it for each body attribute, and type Verifier.verify and NotificationEvent.from_request with the new WebhookRequest union of those.
Point mypy at this checkout and keep its cache in a temp directory.
The per-module directive turned mypy's assignment check off for every enum module. member() returns its value typed as Any, so the annotation type-checks with every checker, and members are still typed as the enum.
Any request object with a body, content or data attribute works at runtime, so type verify() and from_request() as Any rather than a precise protocol. Request goes back to its previous definition.
verify() and from_request() now take Request | BodyRequest | ContentRequest | DataRequest: the existing Request protocol, or any object with headers and a body, content or data attribute. A None body attribute is skipped instead of raising AttributeError.
davidgrayston-paddle
force-pushed
the
fix/py-typed
branch
from
November 20, 2026 15:54
0ee7515 to
6d5ed88
Compare
davidgrayston-paddle
marked this pull request as ready for review
November 23, 2026 10:22
Note in the changelog that a bare CreateReport annotation now fails mypy --strict.
mikeymike
approved these changes
Nov 24, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Added
py.typedmarker, so mypy and pyright check your code against the SDK's type annotations. Package__init__modules now re-export their names explicitly, so imports such asfrom paddle_billing import Clientpass type checkersBodyRequest,ContentRequestandDataRequestprotocols topaddle_billing.Notifications.Requests, for typing your own webhook request objectsChanged
client.customers.responseisResponse | None, and fields the API can return asnullare optional. Undermypy --strict, a bareCreateReportannotation needs type arguments, such asCreateReport[Any, Any]. Pyright already read the SDK's annotationsVerifier.verify()andNotificationEvent.from_request()takeRequest | BodyRequest | ContentRequest | DataRequest, so Django, Flask, httpx and requests request objects pass type checkersFixed
Verifier(maximum_variance=None)no longer raises aTypeErroronverify().Noneskips the time drift check, like0Verifier.verify()andNotificationEvent.from_request()skip abody,contentordataattribute that isNoneand read the next one, instead of raisingAttributeErrorNotificationPayout.from_dict()no longer raisesTypeError: 'module' object is not callablepaddle_billing.Notifications.Events.PaymentMethodDeletedno longer raises anImportErrorThese entries are in
CHANGELOG.mdunder Unreleased.The branch is rebased onto main, which brought in the API key modules. They get the same typing fixes as the rest of the SDK: explicit re-exports,
member()enum declarations andApiKeysClient.responsetyped asResponse | None.Why the re-exports are needed
Adding
py.typedon its own breaks the SDK's documented imports for pyright users.Type checkers apply stricter rules to packages that ship
py.typed(PEP 484, typing spec). In a typed package, a name imported into an__init__.pywith a plainfrom module import Namecounts as private to that module, not as part of the package's public interface. Onlyfrom module import Name as Name, or listing the name in__all__, marks it as re-exported.Every
__init__.pyin the SDK used the plain form. Without this change, pyright reports an error on imports that the README uses:mypy --strictreports the same thing (Module "paddle_billing" does not explicitly export attribute "Client"). Without the marker neither check runs, which is why this hasn't come up before.The
__init__changes were generated mechanically:Name as Namefor each import, and__all__in the five modules that import a name under a different one (for exampleIncludes as PriceIncludes), because a rename is only public through__all__. Those__all__lists also name the subpackage modules thatfrom ...Operations import *picked up before, such asList,Price,CreateandUpdate, so star imports export the same names as before; a test pins them. Imports that the typing changes left unused but that worked before, such asRequestfromNotificationEventandReportTypeandReportFilterfromCreateReport, are kept so they still work, and re-exported so type checkers accept them too. Otherwise runtime behaviour is unchanged.Why the webhook request parameter is a union of protocols
verify()andfrom_request()were typed with theRequestprotocol, which requiresbody,contentanddatatogether as settable attributes. No framework request has all three (Django hasbody, Flask hasdata, httpx and requests havecontent), and frameworks expose them as read-only properties. So once the package is typed, mypy and pyright would rejectVerifier().verify(request, ...)for Django, Flask, httpx and requests, and for a custom class that has only abody.The parameter is now a union of the existing
Requestprotocol and three read-only protocols,BodyRequest,ContentRequestandDataRequest, each needingheadersand one body attribute. That matches what the SDK reads at runtime, keeps existingRequestimplementations valid, and still rejects objects with no body attribute.headersis typedAnyin the new protocols, because Django's, Flask's and requests' header types don't match aget()protocol in both mypy and pyright. Checked with mypy--strict(with django-stubs) and pyright against real Django, Flask, httpx and requests objects.One small runtime change: a body attribute set to
Noneis now skipped, and the SDK moves on to the next attribute, instead of raisingAttributeError.Why the other type fixes are in this PR
The marker publishes the SDK's annotations, so they need to be right when it ships.
mypy paddle_billingreported 1,793 errors:Active: "Status" = "active"). The annotation is deliberate: it makesStatus.Activean instance ofStatusfor type checkers. Members are now declared with a small helper,Active: "Status" = member("active"), which returns its value typed asAny, so the annotation type-checks without disabling any check. Runtime values are identical for all 162 enums, and a member declared the old way fails mypy.PaymentMethodDeletedimport error is caught.mypy paddle_billingis now clean and runs in the lint workflow, so new annotation errors fail CI. pyright reports no errors overpaddle_billing. It does report warnings where those__all__lists name subpackage modules, which pyright can't see as imported; they don't affect users.Type-checking tests
tests/Unit/Typingrunsmypy --strictfrom pytest over usage files written the way users write code: the README examples, and webhook verification with Django-, Flask- and httpx-shaped requests, a custom request and aRequestimplementation. It also checks that invalid usage is still rejected, including a request with no body attribute, so the test can't pass just because the types went missing. It fails if the re-exports or the webhook fix are reverted.tests/Unit/test_PackageExports.pyfails if a package__init__.pyimports a name without re-exporting it.mypyis added to thedevextras.Reviewing
The changes are split into single-purpose commits, so it's easiest to review commit by commit. The
__init__re-exports and themember()rewrite are mechanical and large; the annotation fixes and bug fixes are small and hand-written.Verification
The marker is shipped through
package_data, so it's included in both the wheel and the sdist. With the package installed from this branch, a script using the SDK's documented imports passes bothpyrightandmypy --strict.examples/has no new type errors.Closes #171