Async-first codegen: single source of truth with sync generation#13
Merged
Async-first codegen: single source of truth with sync generation#13
Conversation
Make _async/ the sole hand-written source for all domain and client modules. A deterministic generator (scripts/generate_sync.py) produces _sync/ via regex transforms (async def→def, await removal, asyncio→time, httpx.AsyncClient→Client, class renames). Top-level modules become thin facades preserving all existing import paths. - Create pykalshi/_async/ with 9 standalone async modules - Create scripts/generate_sync.py (--write / --check modes, allowlist validation, stale-file detection) - Replace 10 top-level modules with re-export facades - Add tests/test_codegen.py golden test - Fix pyproject.toml package discovery to include subpackages - Update mock paths in test_portfolio.py Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
576f724 to
7246b14
Compare
Minor bump: async classes no longer inherit from sync counterparts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
_async/the single hand-written source of truth for all domain and client modules (9 files)scripts/generate_sync.pythat deterministically produces_sync/via regex transforms (async def→def,awaitremoval,asyncio.sleep→time.sleep,httpx.AsyncClient→Client,AsyncX→Xclass renames)pyproject.tomlpackage discovery to include_asyncand_syncsubpackagesDetails
Generator (
scripts/generate_sync.py):--writemode for development,--checkmode for CI (exits non-zero on drift)_async/Net result: ~1,200 lines of previously hand-duplicated sync/async code are now maintained in one place. The sync variant is always derivable.
Test plan
pytest tests/ --ignore=tests/integration)python scripts/generate_sync.py --checkexits 0tests/test_codegen.pypassesfrom pykalshi import ...,from pykalshi.client import ..., etc.)--writeproduces no diff)setuptools.find_packages(include=["pykalshi*"])discoverspykalshi._asyncandpykalshi._sync🤖 Generated with Claude Code