Commit ff0b8cb
authored
perf: defer optional typing imports (#634)
## Summary
- resolve heavy optional typing exports lazily on first access
- preserve precise analyzer-visible vendor types when their extras are
installed
- preserve stable runtime shims and Protocol fallbacks when optional
dependencies are absent
- defer optional imports in serializers, storage, schema, and type-guard
consumers
- keep `DEFAULT_TYPE_ENCODERS` fully dict-compatible with thread-safe,
failure-retryable lazy registration
## Compatibility
Users do not need optional libraries installed for SQLSpec imports or
runtime annotations to work. Missing dependencies resolve to stable
cached shims; installed dependencies retain their precise static vendor
types. In a no-extras consumer type-checking environment, optional
vendor aliases resolve as `Any` because the vendor type definitions are
unavailable; the explicit SQLSpec Stub and Protocol types remain
available where callers need a dependency-independent contract.
Public exports, `dir()`, identity, pickle/repr behavior, cattrs fallback
names, dict mutation/union behavior, and runtime type-adapter behavior
are covered.
## Performance
Bare `import sqlspec` median time decreased from 681 ms to 202.467 ms
(70.27%). The import regression guard confirms pandas, polars, PyArrow,
Litestar, Pydantic, OpenTelemetry, and Prometheus are not imported
eagerly.
## Validation
- lazy-export, fallback-shim, optional-boundary, serializer, storage,
concurrency, retry, and dict-contract tests
- Ruff, mypy, pyright, docs, compiled acceptance tests, and MyPyC wheel
build
- full GitHub unit/integration matrix on Python 3.10-3.14
All required GitHub checks pass on the final commit.1 parent 7855fd0 commit ff0b8cb
18 files changed
Lines changed: 1091 additions & 284 deletions
File tree
- docs/reference
- sqlspec
- storage/backends
- utils
- serializers
- tests
- typing
- unit
- tools
- utils
- serializers
- tools/scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
10 | 33 | | |
11 | 34 | | |
12 | 35 | | |
| |||
0 commit comments