refactor: codebase modernization, quality tooling, and API correctness fixes#56
Merged
LegendEvent merged 18 commits intodevfrom Apr 2, 2026
Merged
refactor: codebase modernization, quality tooling, and API correctness fixes#56LegendEvent merged 18 commits intodevfrom
LegendEvent merged 18 commits intodevfrom
Conversation
…orts, add type hints
…lent error swallowing in similardevices
Apply consistent PEP 8 style transformations to all remaining Python files, matching the pattern already applied to 11 files in a previous commit. Changes are purely mechanical with zero logic modifications: - Single to double quotes for all string literals - PEP 8 import ordering (stdlib > third-party > local) - Remove unused `import requests` from endpoint modules - Trailing commas on multi-line function signatures - Multi-line `_make_request` call formatting - Remove trailing whitespace, ensure trailing newlines - Type hint improvements (`int = None` to `Optional[int] = None`) Files changed: darktrace/__init__.py, auth.py darktrace/dt_antigena.py, dt_breaches.py, dt_components.py, dt_cves.py, dt_details.py, dt_deviceinfo.py, dt_devicesearch.py, dt_email.py, dt_endpointdetails.py, dt_enums.py, dt_intelfeed.py, dt_mbcomments.py, dt_metrics.py, dt_models.py, dt_pcaps.py, dt_status.py, dt_summarystatistics.py examples/intelfeed_example.py, threat_intelligence.py Verified: all 22 files pass py_compile, package imports OK (v0.9.0), 90 tests pass / 0 fail, scope fidelity confirmed (style-only changes). Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
- Add [tool.ruff] config: target-version py37, line-length 120 - Configure lint rules: E, F, W, I, UP (ignore E501 for docstrings) - Configure format: double quotes, space indentation - Configure isort: known-first-party darktrace - Add [project.optional-dependencies] dev group: ruff, pytest, pre-commit - Exclude examples/ from ruff checks
- Replace _UNSET = object() with _Unset singleton class in dt_utils.py
- _Unset has __repr__ ('<UNSET>'), __bool__ (False), singleton via __new__
- Add _InternalTimeoutType = Union[_Unset, None, float, Tuple[float, float]]
- Update _resolve_timeout to use _InternalTimeoutType (no type: ignore needed)
- Remove 24 _UNSET-related # type: ignore[assignment] across 19 modules
- Preserve all return-type # type: ignore[assignment] (unrelated to _UNSET)
- Fix missing Dict/Any imports in dt_subnets.py (F821 bug)
- Add # noqa: F401 to __version__ import in __init__.py
- Update test files for ruff formatting compatibility
- One-time ruff format pass on all darktrace/ and root Python files - Import sorting (isort), consistent quote style, whitespace normalization - No logic changes — formatting only - conftest.py: add # noqa: E402 for post-function imports - setup.py: quote style normalization, remove unused os import
- Add .pre-commit-config.yaml with ruff (--fix) and ruff-format hooks - Add .github/workflows/lint.yml with parallel lint + test jobs - Lint job: ruff check + ruff format --check (Python 3.12) - Test job: pip install -e .[dev] + pytest - Triggers on push/PR to main branch
3-phase architecture: - Phase 1: Refresh GitNexus index with embeddings (skippable) - Phase 2: Run 4 Cypher detection checks + allowlist filtering - Phase 3: Dynamic deep investigation for actionable issues Features: - Allowlist for false positives (30 orphaned SDK classes) - LLM-consumable output with rich context - Dynamic investigation queries per issue type - Sisyphus ulw mode trigger for complex issues
- Remove deprecated approve_action method from dt_antigena.py - Remove corresponding test from test_mock.py - Replace bare except Exception with specific exception types (requests.exceptions.RequestException, json.JSONDecodeError) in add_comment, acknowledge, unacknowledge methods Code smells detected by GitNexus code intelligence hook.
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Add real activate_action() method that POSTs to /antigena with activate:true. Fix approve_action() deprecation message to no longer reference the previously missing activate_action method. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Restore approve_action and activate_action assertions in test_antigena_methods. Restore TestDeprecations class with test_approve_action_deprecated. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
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
This PR is a comprehensive housekeeping pass across the entire SDK — cleaning up code quality, hardening error handling, adding developer tooling, and fixing a handful of real bugs found along the way. The changes touch every endpoint module, but the public API surface is fully backwards-compatible.
What changed
🔧 Code quality & consistency
_UNSETsentinel replaced with a properly typed class__all__exports to every module for cleanfrom darktrace.dt_antigena import *behavior__repr__to core classes for better debugging experience🐛 Bug fixes
dt_antigena.py: Restoredactivate_action()— a real API method that was accidentally removed. It POSTs{"codeid": X, "activate": true}to/antigenaper the official Darktrace API specdt_antigena.py: Fixedapprove_action()deprecation message — it was pointing users to the non-existentactivate_action(). Now correctly states it's a no-op for backwards compatibilitydt_advanced_search.py: Restored missingtimeparameter default in GET pathdt_similardevices.py: Fixed silent error swallowing (bareexcept Exception→ specific exception types)dt_breaches.py: Fixed bareexcept Exceptionhandlers inadd_comment,acknowledge,unacknowledge🏗️ Internal refactoring
dt_utils.pywith structured logging,_get/_post_form/_post_jsonhelper methods, and__repr__dt_analyst.pyanddt_breaches.pyto use the newBaseEndpointhelpers🧪 Tests
test_sdk_readonly.pyandtest_mock.pyTestDeprecationsclass to verifyapprove_action()emits the correct warning⚙️ Developer tooling
pyproject.toml)Files changed: 48 · +2,338 / -1,334
Testing
pytest tests/test_mock.py— 81 passedpytest tests/test_compilation.py— all modules compile cleanlypython3 -m py_compile— all modified files pass syntax checkpytest tests/test_sdk_readonly.py— requires authenticated Darktrace instance (51 passed, 10 skipped, 0 failed in last run)Backwards compatibility
No breaking changes. All existing method signatures, return types, and behavior are preserved. The
approve_action()backwards-compat shim is retained with a corrected deprecation notice.