taipanstack 0.4.8__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {taipanstack-0.4.8 → taipanstack-0.5.0}/PKG-INFO +9 -15
  2. {taipanstack-0.4.8 → taipanstack-0.5.0}/README.md +8 -14
  3. {taipanstack-0.4.8 → taipanstack-0.5.0}/pyproject.toml +12 -36
  4. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/__init__.py +1 -1
  5. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/bridges/db_bridge.py +23 -12
  6. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/bridges/http_bridge.py +6 -9
  7. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/bridges/web_bridge.py +6 -8
  8. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/config/generators.py +9 -10
  9. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/config/models.py +4 -4
  10. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/core/optimizations.py +35 -22
  11. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/core/result.py +10 -21
  12. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/adaptive_breaker.py +5 -6
  13. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/orchestrator.py +13 -15
  14. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/circuit_breaker.py +71 -69
  15. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/resilience.py +8 -10
  16. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/retry.py +64 -30
  17. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/_base.py +6 -2
  18. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/config_watcher.py +15 -21
  19. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/health_pinger.py +35 -30
  20. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/resource_watcher.py +4 -5
  21. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/decorators.py +6 -6
  22. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/guards.py +9 -1
  23. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/jwt.py +24 -4
  24. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/sanitizers.py +24 -21
  25. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/types.py +5 -48
  26. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/validators.py +4 -5
  27. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/cache.py +23 -30
  28. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/filesystem.py +9 -7
  29. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/logging.py +57 -9
  30. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/rate_limit.py +38 -21
  31. {taipanstack-0.4.8 → taipanstack-0.5.0}/LICENSE +0 -0
  32. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/bridges/__init__.py +0 -0
  33. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/bridges/_imports.py +0 -0
  34. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/config/__init__.py +0 -0
  35. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/config/version_config.py +0 -0
  36. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/core/__init__.py +0 -0
  37. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/core/compat.py +0 -0
  38. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/__init__.py +0 -0
  39. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/__init__.py +0 -0
  40. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/adaptive_retry.py +0 -0
  41. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/adaptive/bulkhead.py +0 -0
  42. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/resilience/watchdogs/__init__.py +0 -0
  43. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/__init__.py +0 -0
  44. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/models.py +0 -0
  45. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/security/password.py +0 -0
  46. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/__init__.py +0 -0
  47. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/circuit_breaker.py +0 -0
  48. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/concurrency.py +0 -0
  49. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/context.py +0 -0
  50. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/resilience.py +0 -0
  51. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/retry.py +0 -0
  52. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/serialization.py +0 -0
  53. {taipanstack-0.4.8 → taipanstack-0.5.0}/src/taipanstack/utils/subprocess.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: taipanstack
3
- Version: 0.4.8
3
+ Version: 0.5.0
4
4
  Summary: TaipanStack - Modular, secure, and scalable Python stack for robust development
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -87,12 +87,11 @@ Description-Content-Type: text/markdown
87
87
 
88
88
  Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
89
89
 
90
- ### ✨ What's New in v0.4.8
91
- - **Hardening Resilience**: Hardened `RateLimiter` and `CircuitBreaker` against state corruption and type mutations via chaos testing (PR #689, #684).
92
- - **Complexity Reduction**: Major reduction of cyclomatic complexity across core modules, subprocess utilities, and web bridges (PR #706, #692).
93
- - **Security Hardening**: Restored missing type guard for password verification and enhanced durability of atomic writes (Commit f83b6745, PR #688).
94
- - **Performance**: Implemented concurrent execution for async health checks in `HealthPinger` (PR #694).
95
- - **Total Stack Coverage**: Reached **1,315 passing tests** with 100% verified genuine coverage across all modules.
90
+ ### ✨ What's New in v0.5.0
91
+ - **Security Hardening**: Hardened path traversal protection (PR #741) and JWT encoding/decoding logic (PR #775) against malformed inputs; fixed IndexError on project validator (PR #768).
92
+ - **Resilience Enhancements**: Frozen circuit breaker configuration to prevent runtime mutations under chaos (PR #778) and resolved double-wrapping of Result objects in ResilienceOrchestrator (PR #767).
93
+ - **Clean Code & Type Guards**: Enforced strict isinstance type checks to replace match/case result matching (PR #746, #763, #777) and optimized modules to reduce complexity (PR #770).
94
+ - **QA Suite Optimization**: Consolidated and refactored the entire test suite down to **1,225 passing tests** while maintaining absolute 100% genuine code and branch coverage (PR #773, #781, #782).
96
95
 
97
96
  <table>
98
97
  <tr>
@@ -112,7 +111,6 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
112
111
  - `uvloop` async event loop
113
112
  - `orjson` fast JSON serialization
114
113
  - `Pydantic v2` validation
115
- - Performance benchmarks with regression detection
116
114
 
117
115
  </td>
118
116
  </tr>
@@ -130,7 +128,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
130
128
 
131
129
  ### 🔧 Developer Experience
132
130
  - Pre-configured quality tools
133
- - **100% code coverage** (1315 tests)
131
+ - **100% code coverage** (1,225 tests)
134
132
  - Architecture enforcement
135
133
  - Hardened Docker template
136
134
 
@@ -172,7 +170,7 @@ make all
172
170
  ### Verify Installation
173
171
 
174
172
  ```bash
175
- # Run tests with 100% coverage (1315 tests)
173
+ # Run tests with 100% coverage (1,225 tests)
176
174
  make test
177
175
 
178
176
  # Check architecture contracts
@@ -184,8 +182,6 @@ make security
184
182
  # Run property-based fuzzing
185
183
  make property-test
186
184
 
187
- # Run performance benchmarks
188
- make benchmark
189
185
  ```
190
186
 
191
187
  ---
@@ -227,7 +223,7 @@ TaipanStack/
227
223
  │ ├── config/ # ⚙️ Configuration models & generators
228
224
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
229
225
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
230
- ├── tests/ # ✅ 1315 tests, 100% coverage
226
+ ├── tests/ # ✅ 1,225 tests, 100% coverage
231
227
  ├── .semgrep/ # 🔍 Custom SAST rules
232
228
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
233
229
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -250,7 +246,6 @@ Taipan Stack integrates security and quality at every level:
250
246
  | **Lint** | Ruff | Lightning-fast linting & formatting |
251
247
  | **Arch** | Import Linter | Dependency rule enforcement |
252
248
  | **Test** | Pytest, Hypothesis, mutmut | Property-based & mutation testing |
253
- | **Perf** | pytest-benchmark | Performance regression detection |
254
249
  | **Containers** | Docker (Alpine, rootless) | Hardened-by-default images |
255
250
 
256
251
  ### CI Pipeline
@@ -451,7 +446,6 @@ Security features: multi-stage build, Alpine base (<50MB), non-root `appuser` (U
451
446
  - Bandit
452
447
  - Pytest + Hypothesis
453
448
  - mutmut
454
- - pytest-benchmark
455
449
 
456
450
  </td>
457
451
  <td>
@@ -30,12 +30,11 @@
30
30
 
31
31
  Taipan Stack is a battle-tested foundation for production-grade Python projects that combines **security**, **performance**, and **developer experience** into a single, cohesive toolkit.
32
32
 
33
- ### ✨ What's New in v0.4.8
34
- - **Hardening Resilience**: Hardened `RateLimiter` and `CircuitBreaker` against state corruption and type mutations via chaos testing (PR #689, #684).
35
- - **Complexity Reduction**: Major reduction of cyclomatic complexity across core modules, subprocess utilities, and web bridges (PR #706, #692).
36
- - **Security Hardening**: Restored missing type guard for password verification and enhanced durability of atomic writes (Commit f83b6745, PR #688).
37
- - **Performance**: Implemented concurrent execution for async health checks in `HealthPinger` (PR #694).
38
- - **Total Stack Coverage**: Reached **1,315 passing tests** with 100% verified genuine coverage across all modules.
33
+ ### ✨ What's New in v0.5.0
34
+ - **Security Hardening**: Hardened path traversal protection (PR #741) and JWT encoding/decoding logic (PR #775) against malformed inputs; fixed IndexError on project validator (PR #768).
35
+ - **Resilience Enhancements**: Frozen circuit breaker configuration to prevent runtime mutations under chaos (PR #778) and resolved double-wrapping of Result objects in ResilienceOrchestrator (PR #767).
36
+ - **Clean Code & Type Guards**: Enforced strict isinstance type checks to replace match/case result matching (PR #746, #763, #777) and optimized modules to reduce complexity (PR #770).
37
+ - **QA Suite Optimization**: Consolidated and refactored the entire test suite down to **1,225 passing tests** while maintaining absolute 100% genuine code and branch coverage (PR #773, #781, #782).
39
38
 
40
39
  <table>
41
40
  <tr>
@@ -55,7 +54,6 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
55
54
  - `uvloop` async event loop
56
55
  - `orjson` fast JSON serialization
57
56
  - `Pydantic v2` validation
58
- - Performance benchmarks with regression detection
59
57
 
60
58
  </td>
61
59
  </tr>
@@ -73,7 +71,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
73
71
 
74
72
  ### 🔧 Developer Experience
75
73
  - Pre-configured quality tools
76
- - **100% code coverage** (1315 tests)
74
+ - **100% code coverage** (1,225 tests)
77
75
  - Architecture enforcement
78
76
  - Hardened Docker template
79
77
 
@@ -115,7 +113,7 @@ make all
115
113
  ### Verify Installation
116
114
 
117
115
  ```bash
118
- # Run tests with 100% coverage (1315 tests)
116
+ # Run tests with 100% coverage (1,225 tests)
119
117
  make test
120
118
 
121
119
  # Check architecture contracts
@@ -127,8 +125,6 @@ make security
127
125
  # Run property-based fuzzing
128
126
  make property-test
129
127
 
130
- # Run performance benchmarks
131
- make benchmark
132
128
  ```
133
129
 
134
130
  ---
@@ -170,7 +166,7 @@ TaipanStack/
170
166
  │ ├── config/ # ⚙️ Configuration models & generators
171
167
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
172
168
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
173
- ├── tests/ # ✅ 1315 tests, 100% coverage
169
+ ├── tests/ # ✅ 1,225 tests, 100% coverage
174
170
  ├── .semgrep/ # 🔍 Custom SAST rules
175
171
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
176
172
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -193,7 +189,6 @@ Taipan Stack integrates security and quality at every level:
193
189
  | **Lint** | Ruff | Lightning-fast linting & formatting |
194
190
  | **Arch** | Import Linter | Dependency rule enforcement |
195
191
  | **Test** | Pytest, Hypothesis, mutmut | Property-based & mutation testing |
196
- | **Perf** | pytest-benchmark | Performance regression detection |
197
192
  | **Containers** | Docker (Alpine, rootless) | Hardened-by-default images |
198
193
 
199
194
  ### CI Pipeline
@@ -394,7 +389,6 @@ Security features: multi-stage build, Alpine base (<50MB), non-root `appuser` (U
394
389
  - Bandit
395
390
  - Pytest + Hypothesis
396
391
  - mutmut
397
- - pytest-benchmark
398
392
 
399
393
  </td>
400
394
  <td>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "taipanstack"
3
- version = "0.4.8"
3
+ version = "0.5.0"
4
4
  description = "TaipanStack - Modular, secure, and scalable Python stack for robust development"
5
5
  authors = [
6
6
  {name = "gabrielima7", email = "gabrielima.alu.lmb@gmail.com"}
@@ -60,18 +60,13 @@ resilience = [
60
60
  "psutil (>=5.9.0)",
61
61
  ]
62
62
  all = [
63
- # runtime
64
63
  "uvloop (>=0.19.0); sys_platform != 'win32'",
65
64
  "structlog (>=23.0.0)",
66
- # bridges-web
67
65
  "fastapi (>=0.100.0)",
68
66
  "litestar (>=2.0.0)",
69
- # bridges-http
70
67
  "httpx (>=0.24.0)",
71
- # bridges-db
72
68
  "sqlalchemy (>=2.0.0)",
73
69
  "redis (>=5.0.0)",
74
- # resilience
75
70
  "psutil (>=5.9.0)",
76
71
  ]
77
72
 
@@ -94,10 +89,10 @@ dev = [
94
89
  "structlog (>=25.5.0,<26.0.0)",
95
90
  "import-linter (>=2.1)",
96
91
  "gitingest (>=0.1.0)",
97
- "pytest-benchmark (>=5.0.0)",
98
92
  "pytest-asyncio (>=0.23.0)",
99
- "radon (>=6.0.1,<7.0.0)",
100
93
  "pip-audit (>=2.10.0,<3.0.0)",
94
+ "cyclonedx-python-lib (>=11.7.0,<12.0.0)",
95
+ "radon (>=6.0.1,<7.0.0)",
101
96
  # Security: CVE fix - requests <2.33.0 has insecure temp file reuse (CWE-377)
102
97
  # Dependabot alert #17 - CVSS 4.4/10 Moderate
103
98
  "requests (>=2.33.0)",
@@ -108,19 +103,17 @@ dev = [
108
103
  "hypothesis (>=6.151.12,<7.0.0)",
109
104
  "authlib (>=1.6.11,<2.0.0)",
110
105
  "cryptography (>=46.0.7,<49.0.0)",
111
- "nltk (>=3.9.4,<4.0.0)",
112
106
  "mutmut (>=3.0.0,<4.0.0)",
113
- "pip (>=26.1,<27.0)",
114
107
  ]
115
108
 
116
-
117
-
118
-
119
- # --- TaipanStack v2.0 Quality Configuration ---
120
109
  docs = [
121
110
  "mkdocs-material (>=9.7.3,<10.0.0)",
122
111
  "mkdocstrings[python] (>=1.0.3,<2.0.0)"
123
112
  ]
113
+
114
+
115
+
116
+
124
117
  [tool.ruff]
125
118
  line-length = 88
126
119
  target-version = "py311"
@@ -203,8 +196,7 @@ plugins = ["pydantic.mypy"]
203
196
 
204
197
  [[tool.mypy.overrides]]
205
198
  module = [
206
- "pydantic.*",
207
- "mutmut.*",
199
+ "mutmut.*",
208
200
  ]
209
201
  ignore_missing_imports = true
210
202
  ignore_errors = true
@@ -216,18 +208,13 @@ warn_required_dynamic_aliases = true
216
208
 
217
209
  [tool.pytest.ini_options]
218
210
  testpaths = ["tests"]
219
- addopts = "-v --strict-markers --timeout=30"
211
+ addopts = "-v --strict-markers --timeout=30 --cov=src --cov-report=html --cov-report=term-missing"
220
212
  asyncio_mode = "auto"
221
213
  asyncio_default_fixture_loop_scope = "function"
222
214
  markers = [
223
215
  "slow: marks tests as slow (deselect with '-m \"not slow\"')",
224
216
  "security: marks tests as security-related",
225
217
  "integration: marks tests as integration tests",
226
- "benchmark: marks tests as performance benchmarks",
227
- ]
228
- filterwarnings = [
229
-
230
- "ignore::pytest.PytestUnraisableExceptionWarning",
231
218
  ]
232
219
 
233
220
  [tool.coverage.run]
@@ -237,37 +224,26 @@ omit = ["*/tests/*", "*/__pycache__/*", "*/conftest.py"]
237
224
 
238
225
  [tool.coverage.report]
239
226
  exclude_lines = [
240
- "pragma: no cover",
241
- "def __repr__",
242
- "raise NotImplementedError",
227
+
243
228
  "if TYPE_CHECKING:",
244
229
  "if __name__ == .__main__.:",
245
230
  "@abstractmethod",
246
231
  "@overload",
247
232
  "def __call__\\(.*\\) -> .*:\\s*(?:\"\"\".*?\"\"\"\\s*)?\\.\\.\\.",
248
233
  ]
249
- partial_branches = [
250
- "pragma: no branch",
251
- "case Err\\(",
252
- "case Ok\\(",
253
- ]
254
234
  fail_under = 100
255
235
  show_missing = true
256
236
 
257
- [tool.bandit]
258
- exclude_dirs = ["tests", ".venv", "venv"]
259
- skips = ["B101"]
260
237
 
261
238
  [tool.vulture]
262
239
  min_confidence = 80
263
240
  paths = ["src"]
264
- exclude = ["tests"]
241
+
265
242
 
266
243
 
267
244
  [tool.mutmut]
268
245
  paths_to_mutate = ["src/taipanstack/security/sanitizers.py", "src/taipanstack/security/validators.py", "src/taipanstack/security/guards.py", "src/taipanstack/resilience/retry.py", "src/taipanstack/resilience/circuit_breaker.py"]
269
- tests_dir = ["tests/test_property_sanitizers_operations_expected.py", "tests/test_security_validators_operations_expected.py", "tests/test_security_guards_operations_expected.py", "tests/test_security_ssrf_operations_expected.py", "tests/test_utils_retry_operations_expected.py", "tests/test_utils_circuit_breaker_operations_expected.py"]
246
+ tests_dir = ["tests/test_property_sanitizers_operations.py", "tests/test_security_validators_operations.py", "tests/test_security_guards_operations.py", "tests/test_security_ssrf_operations.py", "tests/test_utils_retry_operations.py", "tests/test_utils_circuit_breaker_operations.py"]
270
247
  also_copy = ["src/"]
271
248
  runner = "python -m pytest -x -q --tb=no --timeout=10 --no-cov"
272
- dict_synonyms = "Struct, NamedStruct"
273
249
 
@@ -5,7 +5,7 @@ A modular, secure, and scalable Python stack for robust development.
5
5
  Supports Python 3.11+ with version-aware optimizations for 3.13/3.14.
6
6
  """
7
7
 
8
- __version__ = "0.4.8"
8
+ __version__ = "0.5.0"
9
9
 
10
10
  from taipanstack.config.version_config import (
11
11
  VersionRecommendations,
@@ -231,6 +231,23 @@ class ResilientRedis:
231
231
  self._client = client
232
232
  self._circuit_breaker = circuit_breaker
233
233
 
234
+ def _check_redis_dependencies(self) -> Result[None, Exception]:
235
+ if not _HAS_REDIS:
236
+ return Err(
237
+ ImportError(
238
+ "redis is required for ResilientRedis. "
239
+ "Install with: pip install taipanstack[bridges-db]"
240
+ )
241
+ )
242
+ return Ok(None)
243
+
244
+ def _check_breaker_gate(self) -> Result[None, Exception]:
245
+ if self._circuit_breaker is not None:
246
+ cb_err = _breaker_is_open(self._circuit_breaker)
247
+ if cb_err is not None:
248
+ return Err(cb_err)
249
+ return Ok(None)
250
+
234
251
  async def execute(
235
252
  self,
236
253
  command: str,
@@ -246,19 +263,13 @@ class ResilientRedis:
246
263
  ``Ok(result)`` on success, ``Err`` on failure.
247
264
 
248
265
  """
249
- if not _HAS_REDIS:
250
- return Err(
251
- ImportError(
252
- "redis is required for ResilientRedis. "
253
- "Install with: pip install taipanstack[bridges-db]"
254
- )
255
- )
266
+ dep_result = self._check_redis_dependencies()
267
+ if isinstance(dep_result, Err):
268
+ return dep_result
256
269
 
257
- # Circuit breaker gate
258
- if self._circuit_breaker is not None:
259
- cb_err = _breaker_is_open(self._circuit_breaker)
260
- if cb_err is not None:
261
- return Err(cb_err)
270
+ cb_result = self._check_breaker_gate()
271
+ if isinstance(cb_result, Err):
272
+ return cb_result
262
273
 
263
274
  try:
264
275
  fn = getattr(self._client, command.lower())
@@ -126,11 +126,9 @@ def _check_ssrf(url: str, ssrf_protection: bool) -> Result[None, Exception]:
126
126
  return Ok(None)
127
127
 
128
128
  ssrf_result = guard_ssrf(url)
129
- match ssrf_result:
130
- case Err(security_err):
131
- return Err(security_err)
132
- case Ok(): # pragma: no branch
133
- return Ok(None)
129
+ if isinstance(ssrf_result, Err):
130
+ return Err(ssrf_result.err_value)
131
+ return Ok(None)
134
132
 
135
133
 
136
134
  def _should_retry_status(
@@ -156,7 +154,7 @@ async def _handle_http_exception(
156
154
  circuit_breaker: CircuitBreaker | None,
157
155
  ) -> bool:
158
156
  """Handle exception and return True if we should retry, False otherwise."""
159
- if circuit_breaker is not None: # pragma: no branch
157
+ if circuit_breaker is not None:
160
158
  circuit_breaker._record_failure(exc)
161
159
  if retry_config is not None and attempt < max_attempts:
162
160
  delay = calculate_delay(attempt, retry_config)
@@ -314,9 +312,8 @@ class SafeHttpClient:
314
312
  Example:
315
313
  >>> async with SafeHttpClient() as client:
316
314
  ... result = await client.get("https://api.example.com/data")
317
- ... match result:
318
- ... case Ok(response): print(response.json())
319
- ... case Err(e): print(f"Error: {e}")
315
+ ... if isinstance(result, Ok): print(result.unwrap().json())
316
+ ... else: print(f"Error: {result.unwrap_err()}")
320
317
 
321
318
  """
322
319
 
@@ -14,7 +14,7 @@ from collections.abc import Awaitable, Callable, MutableMapping
14
14
  from dataclasses import dataclass
15
15
  from typing import TypeAlias, TypeVar
16
16
 
17
- from taipanstack.core.result import Err, Ok, Result
17
+ from taipanstack.core.result import Ok, Result
18
18
  from taipanstack.utils.rate_limit import RateLimiter
19
19
 
20
20
  logger = logging.getLogger("taipanstack.bridges.web")
@@ -90,11 +90,9 @@ def result_to_response(
90
90
  {"status": 200, "data": {"id": 1}}
91
91
 
92
92
  """
93
- match result:
94
- case Ok(value):
95
- return {"status": status_ok, "data": value}
96
- case Err(error):
97
- return {"status": status_err, "error": str(error)}
93
+ if isinstance(result, Ok):
94
+ return {"status": status_ok, "data": result.ok_value}
95
+ return {"status": status_err, "error": str(result.err_value)}
98
96
 
99
97
 
100
98
  async def _send_json_response(
@@ -256,8 +254,8 @@ class TaipanMiddleware:
256
254
  # Call the actual application
257
255
  try:
258
256
  await self._app(scope, receive, send)
259
- except Exception:
260
- logger.exception("Unhandled exception in ASGI app")
257
+ except Exception as exc:
258
+ logger.exception("Unhandled exception in ASGI app", exc_info=exc)
261
259
  await _send_json_response(
262
260
  send,
263
261
  status=500,
@@ -170,19 +170,18 @@ def _generate_bandit_hook(severity: str) -> str:
170
170
  """
171
171
 
172
172
 
173
- def _generate_safety_hook() -> str:
174
- """Generate Safety pre-commit hook.
173
+ def _generate_pip_audit_hook() -> str:
174
+ """Generate pip-audit pre-commit hook.
175
175
 
176
176
  Returns:
177
- Safety hook YAML string.
177
+ pip-audit hook YAML string.
178
178
 
179
179
  """
180
180
  return """
181
- - repo: https://github.com/pyupio/safety
182
- rev: '3.2.11'
181
+ - repo: https://github.com/pypa/pip-audit
182
+ rev: 'v2.8.0'
183
183
  hooks:
184
- - id: safety
185
- args: ["check", "--json"]
184
+ - id: pip-audit
186
185
  """
187
186
 
188
187
 
@@ -258,8 +257,8 @@ def generate_pre_commit_config(config: StackConfig) -> str:
258
257
  if config.security.enable_bandit:
259
258
  security_hooks.append(_generate_bandit_hook(config.security.bandit_severity))
260
259
 
261
- if config.security.enable_safety:
262
- security_hooks.append(_generate_safety_hook())
260
+ if config.security.enable_pip_audit:
261
+ security_hooks.append(_generate_pip_audit_hook())
263
262
 
264
263
  if config.security.enable_semgrep:
265
264
  security_hooks.append(_generate_semgrep_hook())
@@ -323,7 +322,7 @@ We prioritize security fixes for the latest version (Rolling Release).
323
322
  This project includes multiple layers of security:
324
323
 
325
324
  - **SAST**: Bandit for static security analysis
326
- - **SCA**: Safety/pip-audit for dependency vulnerabilities
325
+ - **SCA**: pip-audit for dependency vulnerabilities
327
326
  - **Secrets**: detect-secrets for preventing credential leaks
328
327
  - **Type Safety**: Mypy + Pydantic for runtime validation
329
328
  - **Runtime Guards**: Protection against path traversal and injection
@@ -29,7 +29,7 @@ class SecurityConfig(BaseModel):
29
29
  Attributes:
30
30
  level: Security strictness level.
31
31
  enable_bandit: Enable Bandit SAST scanner.
32
- enable_safety: Enable Safety dependency checker.
32
+ enable_pip_audit: Enable pip-audit dependency checker.
33
33
  enable_semgrep: Enable Semgrep analysis.
34
34
  enable_detect_secrets: Enable secret detection.
35
35
  bandit_severity: Minimum severity level for Bandit.
@@ -41,7 +41,7 @@ class SecurityConfig(BaseModel):
41
41
  description="Security strictness level",
42
42
  )
43
43
  enable_bandit: bool = Field(default=True, description="Enable Bandit SAST")
44
- enable_safety: bool = Field(default=True, description="Enable Safety SCA")
44
+ enable_pip_audit: bool = Field(default=True, description="Enable pip-audit SCA")
45
45
  enable_semgrep: bool = Field(default=True, description="Enable Semgrep")
46
46
  enable_detect_secrets: bool = Field(
47
47
  default=True, description="Enable secret detection"
@@ -78,7 +78,7 @@ class DependencyConfig(BaseModel):
78
78
  "ruff",
79
79
  "mypy",
80
80
  "bandit",
81
- "safety",
81
+ "pip-audit",
82
82
  "pre-commit",
83
83
  "pytest",
84
84
  "pytest-cov",
@@ -296,7 +296,7 @@ class StackConfig(BaseModel):
296
296
  all_tools_enabled = all(
297
297
  [
298
298
  self.security.enable_bandit,
299
- self.security.enable_safety,
299
+ self.security.enable_pip_audit,
300
300
  self.security.enable_semgrep,
301
301
  self.security.enable_detect_secrets,
302
302
  ]
@@ -228,13 +228,12 @@ def get_optimization_profile(*, force_refresh: bool = False) -> OptimizationProf
228
228
  profile = _get_base_profile()
229
229
 
230
230
  # Adjust for optimization level
231
- match opt_level:
232
- case opt if opt == OPT_LEVEL_NONE:
233
- _cached_optimization_profile = _PROFILE_311
234
- case opt if opt == OPT_LEVEL_AGGRESSIVE and experimental:
235
- _cached_optimization_profile = _build_aggressive_profile(profile)
236
- case _:
237
- _cached_optimization_profile = profile
231
+ if opt_level == OPT_LEVEL_NONE:
232
+ _cached_optimization_profile = _PROFILE_311
233
+ elif opt_level == OPT_LEVEL_AGGRESSIVE and experimental:
234
+ _cached_optimization_profile = _build_aggressive_profile(profile)
235
+ else:
236
+ _cached_optimization_profile = profile
238
237
 
239
238
  return _cached_optimization_profile
240
239
 
@@ -274,14 +273,19 @@ def _apply_gc_freeze(
274
273
  errors: list[str],
275
274
  ) -> None:
276
275
  """Apply GC freeze if supported."""
277
- if profile.gc_freeze_enabled and freeze_after and PY312:
278
- try:
279
- gc.freeze()
280
- applied.append("gc_freeze: enabled")
281
- except Exception as e:
282
- errors.append(f"gc_freeze: {e}")
283
- elif profile.gc_freeze_enabled and not PY312:
276
+ if not profile.gc_freeze_enabled:
277
+ return
278
+ if not PY312:
284
279
  skipped.append("gc_freeze: requires Python 3.12+")
280
+ return
281
+ if not freeze_after:
282
+ return
283
+
284
+ try:
285
+ gc.freeze()
286
+ applied.append("gc_freeze: enabled")
287
+ except Exception as e:
288
+ errors.append(f"gc_freeze: {e}")
285
289
 
286
290
 
287
291
  def _apply_experimental(
@@ -292,9 +296,9 @@ def _apply_experimental(
292
296
  """Check and log experimental features."""
293
297
  if profile.enable_experimental:
294
298
  features = get_features()
295
- if features.has_jit: # pragma: no branch
299
+ if features.has_jit:
296
300
  applied.append("jit: available")
297
- if features.has_free_threading: # pragma: no branch
301
+ if features.has_free_threading:
298
302
  applied.append("free_threading: available")
299
303
  logger.warning(
300
304
  "EXPERIMENTAL FEATURES ENABLED: Stability and security may be affected."
@@ -303,6 +307,20 @@ def _apply_experimental(
303
307
  skipped.append("experimental: requires STACK_ENABLE_EXPERIMENTAL=1")
304
308
 
305
309
 
310
+ def _log_optimization_summary(
311
+ applied: list[str],
312
+ skipped: list[str],
313
+ errors: list[str],
314
+ ) -> None:
315
+ """Log the summary of applied optimizations."""
316
+ if applied:
317
+ logger.debug("Applied optimizations: %s", ", ".join(applied))
318
+ if skipped:
319
+ logger.debug("Skipped optimizations: %s", ", ".join(skipped))
320
+ if errors:
321
+ logger.warning("Optimization errors: %s", ", ".join(errors))
322
+
323
+
306
324
  def apply_optimizations(
307
325
  *,
308
326
  profile: OptimizationProfile | None = None,
@@ -352,12 +370,7 @@ def apply_optimizations(
352
370
 
353
371
  # Log summary
354
372
  success = len(errors) == 0
355
- if applied:
356
- logger.debug("Applied optimizations: %s", ", ".join(applied))
357
- if skipped: # pragma: no branch
358
- logger.debug("Skipped optimizations: %s", ", ".join(skipped))
359
- if errors:
360
- logger.warning("Optimization errors: %s", ", ".join(errors))
373
+ _log_optimization_summary(applied, skipped, errors)
361
374
 
362
375
  return OptimizationResult(
363
376
  success=success,
@@ -13,11 +13,10 @@ Example:
13
13
  ... raise ValueError("division by zero")
14
14
  ... return a / b
15
15
  >>> result = divide(10, 0)
16
- >>> match result:
17
- ... case Err(e):
18
- ... print(f"Error: {e}")
19
- ... case Ok(value):
20
- ... print(f"Result: {value}")
16
+ >>> if isinstance(result, Err):
17
+ ... print(f"Error: {result.err_value}")
18
+ ... else:
19
+ ... print(f"Result: {result.unwrap()}")
21
20
  Error: division by zero
22
21
 
23
22
  """
@@ -281,14 +280,9 @@ async def map_async(
281
280
  Err('fail')
282
281
 
283
282
  """
284
- match result:
285
- case Ok(val):
286
- return Ok(await func(val))
287
- case Err(e):
288
- _ = e
289
- return result
290
- case _:
291
- return result
283
+ if isinstance(result, Ok):
284
+ return Ok(await func(result.ok_value))
285
+ return result
292
286
 
293
287
 
294
288
  @overload
@@ -341,11 +335,6 @@ async def and_then_async(
341
335
  Err(ValueError('No DB'))
342
336
 
343
337
  """
344
- match result:
345
- case Ok(val):
346
- return await func(val)
347
- case Err(e):
348
- _ = e
349
- return result
350
- case _:
351
- return result
338
+ if isinstance(result, Ok):
339
+ return await func(result.ok_value)
340
+ return result