taipanstack 0.4.9__tar.gz → 0.5.1__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.9 → taipanstack-0.5.1}/PKG-INFO +10 -11
  2. {taipanstack-0.4.9 → taipanstack-0.5.1}/README.md +9 -10
  3. {taipanstack-0.4.9 → taipanstack-0.5.1}/pyproject.toml +12 -34
  4. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/__init__.py +1 -1
  5. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/bridges/db_bridge.py +23 -12
  6. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/bridges/http_bridge.py +5 -8
  7. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/bridges/web_bridge.py +4 -6
  8. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/config/generators.py +9 -10
  9. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/config/models.py +4 -4
  10. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/config/version_config.py +0 -4
  11. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/core/compat.py +0 -2
  12. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/core/optimizations.py +33 -20
  13. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/core/result.py +10 -21
  14. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/adaptive/adaptive_breaker.py +58 -24
  15. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/adaptive/adaptive_retry.py +12 -9
  16. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/adaptive/orchestrator.py +32 -25
  17. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/circuit_breaker.py +37 -34
  18. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/resilience.py +18 -12
  19. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/retry.py +41 -24
  20. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/watchdogs/config_watcher.py +29 -21
  21. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/watchdogs/health_pinger.py +18 -20
  22. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/watchdogs/resource_watcher.py +4 -5
  23. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/guards.py +47 -19
  24. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/jwt.py +24 -4
  25. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/sanitizers.py +10 -0
  26. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/types.py +5 -6
  27. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/validators.py +1 -1
  28. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/cache.py +23 -30
  29. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/concurrency.py +3 -2
  30. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/filesystem.py +9 -7
  31. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/logging.py +6 -7
  32. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/rate_limit.py +55 -34
  33. {taipanstack-0.4.9 → taipanstack-0.5.1}/LICENSE +0 -0
  34. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/bridges/__init__.py +0 -0
  35. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/bridges/_imports.py +0 -0
  36. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/config/__init__.py +0 -0
  37. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/core/__init__.py +0 -0
  38. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/__init__.py +0 -0
  39. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/adaptive/__init__.py +0 -0
  40. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/adaptive/bulkhead.py +0 -0
  41. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/watchdogs/__init__.py +0 -0
  42. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/resilience/watchdogs/_base.py +0 -0
  43. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/__init__.py +0 -0
  44. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/decorators.py +0 -0
  45. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/models.py +0 -0
  46. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/security/password.py +0 -0
  47. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/__init__.py +0 -0
  48. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/circuit_breaker.py +0 -0
  49. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/context.py +0 -0
  50. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/resilience.py +0 -0
  51. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/retry.py +0 -0
  52. {taipanstack-0.4.9 → taipanstack-0.5.1}/src/taipanstack/utils/serialization.py +0 -0
  53. {taipanstack-0.4.9 → taipanstack-0.5.1}/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.9
3
+ Version: 0.5.1
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.9
91
- - **100% REAL Coverage**: Achieved true **100% genuine branch coverage** across the entire core without artificial gaps (PR #738, #724).
92
- - **Security Hardening**: Remedied error handling information leakage and fixed nested dictionary redaction in logging (PR #739, #730).
93
- - **Resilience**: Eliminated circuit breaker lock deadlock vector and hardened retry type mutation handling (PR #726, #719).
94
- - **Chaos Testing**: Introduced daily micro-chaos tests for resilience components to ensure state integrity (PR #714, #711, #710).
95
- - **Total Stack Quality**: Expanded to **1,331 passing tests** with 100% verified genuine coverage across all modules.
90
+ ### ✨ What's New in v0.5.1
91
+ - **Security & DoS Hardening**: Enforced configuration file size limits in config watcher (PR #807) and input length bounds on sanitizers (PR #801) to prevent Denial of Service; updated Starlette to `1.0.1` to resolve PYSEC-2026-161 (PR #804).
92
+ - **Resilience Enhancements**: Checked circuit breaker status inside the orchestrator's retry execution loop (PR #783) and hardened resilience decorators against type mutations under chaos (PR #795, #800, #802, #803).
93
+ - **Complexity & Refactoring**: Reduced complexity in rate limiter, circuit breakers, and security guards (PR #786, #798, #805); removed PyApp configuration (PR #784) and dead compatibility logic (PR #788).
94
+ - **QA Suite Standardization**: Standardized test naming convention (`test_*.py`) and removed code/test suite bypasses, expanding to **1,250 passing tests** with 100% genuine code and branch coverage (PR #797, #808).
96
95
 
97
96
  <table>
98
97
  <tr>
@@ -129,7 +128,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
129
128
 
130
129
  ### 🔧 Developer Experience
131
130
  - Pre-configured quality tools
132
- - **100% code coverage** (1,331 tests)
131
+ - **100% code coverage** (1,250 tests)
133
132
  - Architecture enforcement
134
133
  - Hardened Docker template
135
134
 
@@ -171,7 +170,7 @@ make all
171
170
  ### Verify Installation
172
171
 
173
172
  ```bash
174
- # Run tests with 100% coverage (1,331 tests)
173
+ # Run tests with 100% coverage (1,250 tests)
175
174
  make test
176
175
 
177
176
  # Check architecture contracts
@@ -224,7 +223,7 @@ TaipanStack/
224
223
  │ ├── config/ # ⚙️ Configuration models & generators
225
224
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
226
225
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
227
- ├── tests/ # ✅ 1,331 tests, 100% coverage
226
+ ├── tests/ # ✅ 1,250 tests, 100% coverage
228
227
  ├── .semgrep/ # 🔍 Custom SAST rules
229
228
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
230
229
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -240,7 +239,7 @@ Taipan Stack integrates security and quality at every level:
240
239
  | Category | Tools | Purpose |
241
240
  |----------|-------|---------|
242
241
  | **SAST** | Bandit, Semgrep + custom rules | Static Application Security Testing |
243
- | **SCA** | Safety, pip-audit | Dependency vulnerability scanning |
242
+ | **SCA** | pip-audit | Dependency vulnerability scanning |
244
243
  | **SBOM** | Syft (CycloneDX) | Software Bill of Materials |
245
244
  | **SLSA** | Cosign (Sigstore) | Artifact signing & attestation |
246
245
  | **Types** | Mypy (strict) | Compile-time type checking |
@@ -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.9
34
- - **100% REAL Coverage**: Achieved true **100% genuine branch coverage** across the entire core without artificial gaps (PR #738, #724).
35
- - **Security Hardening**: Remedied error handling information leakage and fixed nested dictionary redaction in logging (PR #739, #730).
36
- - **Resilience**: Eliminated circuit breaker lock deadlock vector and hardened retry type mutation handling (PR #726, #719).
37
- - **Chaos Testing**: Introduced daily micro-chaos tests for resilience components to ensure state integrity (PR #714, #711, #710).
38
- - **Total Stack Quality**: Expanded to **1,331 passing tests** with 100% verified genuine coverage across all modules.
33
+ ### ✨ What's New in v0.5.1
34
+ - **Security & DoS Hardening**: Enforced configuration file size limits in config watcher (PR #807) and input length bounds on sanitizers (PR #801) to prevent Denial of Service; updated Starlette to `1.0.1` to resolve PYSEC-2026-161 (PR #804).
35
+ - **Resilience Enhancements**: Checked circuit breaker status inside the orchestrator's retry execution loop (PR #783) and hardened resilience decorators against type mutations under chaos (PR #795, #800, #802, #803).
36
+ - **Complexity & Refactoring**: Reduced complexity in rate limiter, circuit breakers, and security guards (PR #786, #798, #805); removed PyApp configuration (PR #784) and dead compatibility logic (PR #788).
37
+ - **QA Suite Standardization**: Standardized test naming convention (`test_*.py`) and removed code/test suite bypasses, expanding to **1,250 passing tests** with 100% genuine code and branch coverage (PR #797, #808).
39
38
 
40
39
  <table>
41
40
  <tr>
@@ -72,7 +71,7 @@ Taipan Stack is a battle-tested foundation for production-grade Python projects
72
71
 
73
72
  ### 🔧 Developer Experience
74
73
  - Pre-configured quality tools
75
- - **100% code coverage** (1,331 tests)
74
+ - **100% code coverage** (1,250 tests)
76
75
  - Architecture enforcement
77
76
  - Hardened Docker template
78
77
 
@@ -114,7 +113,7 @@ make all
114
113
  ### Verify Installation
115
114
 
116
115
  ```bash
117
- # Run tests with 100% coverage (1,331 tests)
116
+ # Run tests with 100% coverage (1,250 tests)
118
117
  make test
119
118
 
120
119
  # Check architecture contracts
@@ -167,7 +166,7 @@ TaipanStack/
167
166
  │ ├── config/ # ⚙️ Configuration models & generators
168
167
  │ ├── security/ # 🛡️ Guards, sanitizers, validators
169
168
  │ └── utils/ # 🔧 Logging, metrics, retry, filesystem
170
- ├── tests/ # ✅ 1,331 tests, 100% coverage
169
+ ├── tests/ # ✅ 1,250 tests, 100% coverage
171
170
  ├── .semgrep/ # 🔍 Custom SAST rules
172
171
  ├── .github/ # 🔄 CI/CD + SBOM/SLSA workflows
173
172
  ├── Dockerfile # 🐳 Hardened multi-stage container
@@ -183,7 +182,7 @@ Taipan Stack integrates security and quality at every level:
183
182
  | Category | Tools | Purpose |
184
183
  |----------|-------|---------|
185
184
  | **SAST** | Bandit, Semgrep + custom rules | Static Application Security Testing |
186
- | **SCA** | Safety, pip-audit | Dependency vulnerability scanning |
185
+ | **SCA** | pip-audit | Dependency vulnerability scanning |
187
186
  | **SBOM** | Syft (CycloneDX) | Software Bill of Materials |
188
187
  | **SLSA** | Cosign (Sigstore) | Artifact signing & attestation |
189
188
  | **Types** | Mypy (strict) | Compile-time type checking |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "taipanstack"
3
- version = "0.4.9"
3
+ version = "0.5.1"
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
 
@@ -95,8 +90,9 @@ dev = [
95
90
  "import-linter (>=2.1)",
96
91
  "gitingest (>=0.1.0)",
97
92
  "pytest-asyncio (>=0.23.0)",
98
- "radon (>=6.0.1,<7.0.0)",
99
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)",
100
96
  # Security: CVE fix - requests <2.33.0 has insecure temp file reuse (CWE-377)
101
97
  # Dependabot alert #17 - CVSS 4.4/10 Moderate
102
98
  "requests (>=2.33.0)",
@@ -107,19 +103,17 @@ dev = [
107
103
  "hypothesis (>=6.151.12,<7.0.0)",
108
104
  "authlib (>=1.6.11,<2.0.0)",
109
105
  "cryptography (>=46.0.7,<49.0.0)",
110
- "nltk (>=3.9.4,<4.0.0)",
111
106
  "mutmut (>=3.0.0,<4.0.0)",
112
- "pip (>=26.1,<27.0)",
113
107
  ]
114
108
 
115
-
116
-
117
-
118
- # --- TaipanStack v2.0 Quality Configuration ---
119
109
  docs = [
120
110
  "mkdocs-material (>=9.7.3,<10.0.0)",
121
- "mkdocstrings[python] (>=1.0.3,<2.0.0)"
111
+ "mkdocstrings[python] (>=1.0.3,<2.0.0)",
122
112
  ]
113
+
114
+
115
+
116
+
123
117
  [tool.ruff]
124
118
  line-length = 88
125
119
  target-version = "py311"
@@ -202,8 +196,7 @@ plugins = ["pydantic.mypy"]
202
196
 
203
197
  [[tool.mypy.overrides]]
204
198
  module = [
205
- "pydantic.*",
206
- "mutmut.*",
199
+ "mutmut.*",
207
200
  ]
208
201
  ignore_missing_imports = true
209
202
  ignore_errors = true
@@ -215,7 +208,7 @@ warn_required_dynamic_aliases = true
215
208
 
216
209
  [tool.pytest.ini_options]
217
210
  testpaths = ["tests"]
218
- addopts = "-v --strict-markers --timeout=30"
211
+ addopts = "-v --strict-markers --timeout=30 --cov=src --cov-report=html --cov-report=term-missing"
219
212
  asyncio_mode = "auto"
220
213
  asyncio_default_fixture_loop_scope = "function"
221
214
  markers = [
@@ -223,10 +216,6 @@ markers = [
223
216
  "security: marks tests as security-related",
224
217
  "integration: marks tests as integration tests",
225
218
  ]
226
- filterwarnings = [
227
-
228
- "ignore::pytest.PytestUnraisableExceptionWarning",
229
- ]
230
219
 
231
220
  [tool.coverage.run]
232
221
  branch = true
@@ -236,36 +225,25 @@ omit = ["*/tests/*", "*/__pycache__/*", "*/conftest.py"]
236
225
  [tool.coverage.report]
237
226
  exclude_lines = [
238
227
 
239
- "def __repr__",
240
- "raise NotImplementedError",
241
228
  "if TYPE_CHECKING:",
242
229
  "if __name__ == .__main__.:",
243
230
  "@abstractmethod",
244
231
  "@overload",
245
232
  "def __call__\\(.*\\) -> .*:\\s*(?:\"\"\".*?\"\"\"\\s*)?\\.\\.\\.",
246
233
  ]
247
- partial_branches = [
248
-
249
- "case Err\\(",
250
- "case Ok\\(",
251
- ]
252
234
  fail_under = 100
253
235
  show_missing = true
254
236
 
255
- [tool.bandit]
256
- exclude_dirs = ["tests", ".venv", "venv"]
257
- skips = ["B101"]
258
237
 
259
238
  [tool.vulture]
260
239
  min_confidence = 80
261
240
  paths = ["src"]
262
- exclude = ["tests"]
241
+
263
242
 
264
243
 
265
244
  [tool.mutmut]
266
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"]
267
- 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"]
268
247
  also_copy = ["src/"]
269
248
  runner = "python -m pytest -x -q --tb=no --timeout=10 --no-cov"
270
- dict_synonyms = "Struct, NamedStruct"
271
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.9"
8
+ __version__ = "0.5.1"
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():
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(
@@ -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(
@@ -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
  ]
@@ -10,7 +10,6 @@ Following Stack pillars: Security, Stability, Simplicity, Scalability, Compatibi
10
10
 
11
11
  import logging
12
12
  from dataclasses import dataclass
13
- from typing import TYPE_CHECKING
14
13
 
15
14
  from taipanstack.core.compat import (
16
15
  PY312,
@@ -21,9 +20,6 @@ from taipanstack.core.compat import (
21
20
  )
22
21
  from taipanstack.core.optimizations import get_recommended_thread_pool_size
23
22
 
24
- if TYPE_CHECKING:
25
- pass
26
-
27
23
  __all__ = [
28
24
  "VersionRecommendations",
29
25
  "get_version_recommendations",
@@ -223,7 +223,6 @@ class PythonFeatures:
223
223
  has_exception_groups: bool = False # 3.11+
224
224
  has_self_type: bool = False # 3.11+
225
225
  has_type_params: bool = False # 3.12+
226
- has_fstring_improvements: bool = False # 3.12+
227
226
  has_override_decorator: bool = False # 3.12+
228
227
  has_deprecated_decorator: bool = False # 3.13+
229
228
  has_deferred_annotations: bool = False # 3.14+
@@ -283,7 +282,6 @@ def _get_language_features() -> dict[str, bool]:
283
282
  "has_exception_groups": PY311,
284
283
  "has_self_type": PY311,
285
284
  "has_type_params": PY312,
286
- "has_fstring_improvements": PY312,
287
285
  "has_override_decorator": PY312,
288
286
  "has_deprecated_decorator": PY313,
289
287
  "has_deferred_annotations": PY314,
@@ -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(
@@ -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:
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