Repository navigation
fix(client): Keep the public client's type in with WorkOSClient() as workos - #771
Merged
Merged
Conversation
… workos` WorkOSClient.__enter__ and AsyncWorkOSClient.__aenter__ were annotated with the base classes in _base_client.py, so type checkers saw the target of a with statement as a client without any resources or helpers. They return Self now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
[Low impact] The PR appears safe to merge. SummaryThe PR preserves the public client's type inside
Reviews (1) · Last reviewed commit: "fix(client): Keep the public client's ty..." · Reviewed by Greptile |
Deborah-Digges
approved these changes
Nov 5, 2026
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.
Description
with WorkOSClient() as workos:gives type checkers a client without any of its resources.__enter__is annotated-> "WorkOSClient"in_base_client.py, where that name is the base class, not the publicWorkOSClientfrom_client.py.AsyncWorkOSClient.__aenter__has the same problem. The resources (workos.organizations,workos.user_management, …) andcreate_feature_flags_runtime_client()are defined only on the public subclasses, so every one of them is an error on thewithtarget:Anyone who opens a client with
withorasync withand type-checks their code hits this: pyright in its default mode, and mypy in any function it checks (an annotated one, or any with--check-untyped-defs). At runtime nothing changes; both methods already returnself.Both now return
Self, imported fromtypingon 3.11+ and fromtyping_extensionson 3.10, as_types.pyalready does.How I checked it:
test_generated_client.pyuse a resource andcreate_feature_flags_runtime_client()on the target ofwith WorkOSClient(...)andasync with AsyncWorkOSClient(...). CI'spyrightrun coverstests/, so that's the regression check. Onmainit reports 4 errors, such asCannot access attribute "create_feature_flags_runtime_client" for class "WorkOSClient". On this branch it reports 0.async withversion) against this repo's install, with pyright 1.1.408 and mypy 2.4.1:main: mypy finds 3 errors ("WorkOSClient" has no attribute "create_feature_flags_runtime_client" [attr-defined],"WorkOSClient" has no attribute "organizations", and the async one); pyright finds the same 3.Success: no issues found; pyright 0 errors.pyright --pythonversion 3.10on the changed files reports 0 errors, andtest_generated_client.pypasses on Python 3.10.20, which takes thetyping_extensionsimport.ruff format --check,ruff checkandpyrightpass, and the full suite passes: 3,745 tests.Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
No.
🤖 Generated with Claude Code