-
Notifications
You must be signed in to change notification settings - Fork 0
Apply Black and isort formatting to resolve CI failures #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Lexicoding-systems <234111021+Lexicoding-systems@users.noreply.github.com>
|
|
||
| import json | ||
| import os | ||
| import secrets |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused import, you remove the import statement so that only actually used modules remain. This reduces clutter and avoids misleading future maintainers about dependencies.
In this file, the best fix is to delete the import secrets line (line 10) from src/lexecon/api/server.py, leaving all other imports untouched. No other code changes, methods, or definitions are needed because we are only cleaning up an unused dependency. This will not alter runtime behavior since secrets is not referenced anywhere.
| @@ -7,7 +7,6 @@ | ||
|
|
||
| import json | ||
| import os | ||
| import secrets | ||
| import time | ||
| import uuid | ||
| from datetime import datetime, timezone |
| from fastapi import FastAPI, HTTPException, Request, status | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
| from fastapi.responses import HTMLResponse, FileResponse, JSONResponse, PlainTextResponse | ||
| from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused import, remove the unused symbol from the import statement while leaving the rest of the imports intact. This avoids unnecessary dependencies and slightly reduces cognitive load without changing behavior.
Concretely, in src/lexecon/api/server.py, adjust the from fastapi.responses import ... line so that JSONResponse is no longer imported. Keep FileResponse, HTMLResponse, and PlainTextResponse as they are. No other code changes or additions are required, and no new methods, imports, or definitions are needed.
-
Copy modified line R18
| @@ -15,7 +15,7 @@ | ||
|
|
||
| from fastapi import FastAPI, HTTPException, Request, status | ||
| from fastapi.middleware.cors import CORSMiddleware | ||
| from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse | ||
| from fastapi.responses import FileResponse, HTMLResponse, PlainTextResponse | ||
| from pydantic import BaseModel, Field | ||
|
|
||
| from lexecon.audit_export.service import AuditExportService, ExportFormat, ExportScope |
src/lexecon/api/server.py
Outdated
| # Security imports | ||
| from lexecon.security.auth_service import AuthService, Role, Permission, User, Session | ||
| # Governance service imports | ||
| from lexecon.risk.service import RiskScoringEngine, RiskService |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused-import issue, the general approach is to remove the unused symbol from the import statement (or the entire import if none of its symbols are used). This eliminates the unnecessary dependency and matches the CodeQL recommendation.
Here, the best minimal fix without changing functionality is to keep importing RiskService (which is presumably used elsewhere in this file) but stop importing RiskScoringEngine. That means editing the import line at/around line 39 in src/lexecon/api/server.py to remove RiskScoringEngine from the imported names, leaving just from lexecon.risk.service import RiskService. No other methods, imports, or definitions are required.
-
Copy modified line R39
| @@ -36,7 +36,7 @@ | ||
| from lexecon.responsibility.tracker import DecisionMaker, ResponsibilityLevel, ResponsibilityTracker | ||
|
|
||
| # Governance service imports | ||
| from lexecon.risk.service import RiskScoringEngine, RiskService | ||
| from lexecon.risk.service import RiskService | ||
| from lexecon.security.audit_service import AuditService, ExportStatus | ||
|
|
||
| # Security imports |
src/lexecon/api/server.py
Outdated
| ExportScope | ||
| ) | ||
| # Security imports | ||
| from lexecon.security.auth_service import AuthService, Permission, Role, Session, User |
Check notice
Code scanning / CodeQL
Unused import Note
Import of 'User' is not used.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix this kind of problem, we remove any names from import lists that are not actually used in the module. This keeps imports minimal, reduces mental overhead when reading the file, and eliminates unnecessary dependencies flagged by static analysis.
In this file, we should edit the import on line 43 in src/lexecon/api/server.py to remove Session and User from the list of imported symbols, leaving AuthService, Permission, and Role unchanged. No additional methods, definitions, or imports are needed; we’re simply trimming the import list. Care should be taken not to alter other imports or code outside the shown snippet.
-
Copy modified line R43
| @@ -40,7 +40,7 @@ | ||
| from lexecon.security.audit_service import AuditService, ExportStatus | ||
|
|
||
| # Security imports | ||
| from lexecon.security.auth_service import AuthService, Permission, Role, Session, User | ||
| from lexecon.security.auth_service import AuthService, Permission, Role | ||
| from lexecon.security.signature_service import SignatureService | ||
| from lexecon.storage.persistence import LedgerStorage | ||
|
|
| import uuid | ||
| import hashlib | ||
| from dataclasses import dataclass, field | ||
| from datetime import datetime, timedelta, timezone |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused import, you remove the unreferenced symbol from the import statement (or delete the entire import if none of its names are used). This keeps only the actually used identifiers and avoids misleading dependencies.
In this file, datetime and timezone are used in type hints and in the default_factory on line 68, but timedelta is not referenced anywhere in the visible code. The best minimal fix is to edit the import on line 20 in src/lexecon/audit_export/service.py to drop timedelta while leaving datetime and timezone as they are. No additional methods, definitions, or imports are required.
Concretely:
- In
src/lexecon/audit_export/service.py, find the line:from datetime import datetime, timedelta, timezone
- Change it to:
from datetime import datetime, timezone
This preserves all existing functionality and only removes the unused symbol.
-
Copy modified line R20
| @@ -17,7 +17,7 @@ | ||
| import json | ||
| import uuid | ||
| from dataclasses import dataclass, field | ||
| from datetime import datetime, timedelta, timezone | ||
| from datetime import datetime, timezone | ||
| from enum import Enum | ||
| from typing import Any, Dict, List, Optional, Set | ||
|
|
src/lexecon/audit_export/service.py
Outdated
| from dataclasses import dataclass, field | ||
| from datetime import datetime, timedelta, timezone | ||
| from enum import Enum | ||
| from typing import Any, Dict, List, Optional, Set |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix the problem, remove the unused Set symbol from the typing import so that only actually used types are imported. This keeps the code clean and removes an unnecessary dependency without affecting functionality.
Specifically, in src/lexecon/audit_export/service.py, adjust the import on line 22 so that Set is no longer imported. Leave Any, Dict, List, and Optional as they may be used elsewhere in the file. No other methods, imports, or definitions are required for this change.
-
Copy modified line R22
| @@ -19,7 +19,7 @@ | ||
| from dataclasses import dataclass, field | ||
| from datetime import datetime, timedelta, timezone | ||
| from enum import Enum | ||
| from typing import Any, Dict, List, Optional, Set | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
|
|
||
| class ExportFormat(Enum): |
src/lexecon/security/auth_service.py
Outdated
| from enum import Enum | ||
| from typing import Optional, Dict, List, Tuple | ||
| from dataclasses import dataclass | ||
| from typing import Dict, List, Optional, Tuple |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix the problem, the import should be reduced to only the typing symbols that are actually used in this file. Since CodeQL reports that Dict is unused, and we must not assume other unused names beyond what the tool reports, we should remove Dict from the from typing import ... list while leaving List, Optional, and Tuple intact.
Concretely, in src/lexecon/security/auth_service.py, at line 19, change the import line from from typing import Dict, List, Optional, Tuple to from typing import List, Optional, Tuple. No other code changes are required, and this does not alter any runtime behavior because Dict was not referenced anywhere.
-
Copy modified line R19
| @@ -16,7 +16,7 @@ | ||
| from dataclasses import dataclass | ||
| from datetime import datetime, timedelta, timezone | ||
| from enum import Enum | ||
| from typing import Dict, List, Optional, Tuple | ||
| from typing import List, Optional, Tuple | ||
|
|
||
|
|
||
| class Role(str, Enum): |
| from cryptography.hazmat.primitives.asymmetric import rsa, padding | ||
| from cryptography.hazmat.primitives import hashes, serialization | ||
| from cryptography.hazmat.backends import default_backend | ||
| from typing import Any, Dict, Optional, Tuple |
Check notice
Code scanning / CodeQL
Unused import Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused-import problem, you either remove the unused symbol from the import statement or start using it meaningfully in the code. Since there is no apparent need for Optional in the shown type hints, the best way to fix this without changing functionality is to delete Optional from the from typing import ... line.
Concretely, in src/lexecon/security/signature_service.py, on line 15, change the import line from from typing import Any, Dict, Optional, Tuple to from typing import Any, Dict, Tuple. No other code changes are necessary, and no additional methods, imports, or definitions are required.
-
Copy modified line R15
| @@ -12,7 +12,7 @@ | ||
| import json | ||
| import os | ||
| from datetime import datetime, timezone | ||
| from typing import Any, Dict, Optional, Tuple | ||
| from typing import Any, Dict, Tuple | ||
|
|
||
| from cryptography.exceptions import InvalidSignature | ||
| from cryptography.hazmat.backends import default_backend |
| import pytest | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest |
Check notice
Code scanning / CodeQL
Unused import Note test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix an unused import, the general approach is to remove the import statement for the unused module, ensuring that nothing in the file depends on it. This eliminates unnecessary dependencies and cleans up the code.
In this specific case, the best fix is to delete the line import pytest from tests/test_middleware.py. No other changes are needed because the rest of the code does not reference pytest. This does not alter existing test functionality, as the tests rely only on unittest.mock, fastapi.Request, and the lexecon.security modules. Concretely, remove line 5 in the snippet (the import pytest line) and leave the other imports unchanged.
| @@ -2,7 +2,6 @@ | ||
|
|
||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
| from fastapi import Request | ||
|
|
||
| from lexecon.security.auth_service import Permission, Role, Session |
| import pytest | ||
| from fastapi import Request | ||
|
|
||
| from lexecon.security.auth_service import Permission, Role, Session |
Check notice
Code scanning / CodeQL
Unused import Note test
Import of 'Permission' is not used.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix the problem, remove the unused imported names while keeping the used one. In general, unused-import issues are resolved either by deleting the unused imports or by tightening wildcard imports to only the required symbols.
Specifically here, in tests/test_middleware.py at line 8, replace from lexecon.security.auth_service import Permission, Role, Session with an import of only Role, since Permission and Session are never referenced in this file. This change does not alter existing functionality because it only removes unused names and leaves the needed one intact. No additional methods, imports, or definitions are required.
-
Copy modified line R8
| @@ -5,7 +5,7 @@ | ||
| import pytest | ||
| from fastapi import Request | ||
|
|
||
| from lexecon.security.auth_service import Permission, Role, Session | ||
| from lexecon.security.auth_service import Role | ||
| from lexecon.security.middleware import get_current_user, require_permission | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request applies automated code formatting using Black and isort to resolve CI failures. The changes are purely cosmetic, reformatting 46 files with Black (line-length: 100) and correcting import order in 30 files according to the black profile configuration in pyproject.toml.
Key changes:
- String quotes standardized from single to double quotes throughout
- Import statements reordered alphabetically and grouped (stdlib, third-party, first-party)
- Line breaks and wrapping adjusted to comply with 100-character line length
- Trailing commas added to multi-line structures
- Whitespace normalized around operators, function calls, and data structures
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_tracing.py | Quote standardization, line wrapping, blank line additions between decorators and functions |
| tests/test_storage_persistence.py | Import reordering, trailing comma additions, line wrapping for long arguments |
| tests/test_security.py | Import order correction (shutil/tempfile swap), trailing comma addition |
| tests/test_risk_service.py | Import alphabetization, line wrapping for function calls |
| tests/test_policy.py | Trailing comma additions, line wrapping improvements |
| tests/test_override_service.py | Import reordering, line wrapping for long conditionals |
| tests/test_middleware.py | Import order correction, formatting consistency |
| tests/test_metrics.py | Quote standardization, line wrapping for chained method calls |
| tests/test_logging.py | Line wrapping for function calls |
| tests/test_ledger.py | Blank line additions for code organization |
| tests/test_identity.py | Line wrapping, blank line additions for imports |
| tests/test_governance_models.py | Major import statement reorganization with comment preservation |
| tests/test_governance_api.py | Import order correction |
| tests/test_export_determinism.py | Import reordering, line wrapping for conditionals |
| tests/test_evidence_service.py | Import alphabetization, line wrapping |
| tests/test_escalation_service.py | Import reordering, line wrapping for function calls |
| tests/test_decision_service.py | Import organization, line wrapping, blank line additions |
| tests/test_compliance_mapping.py | Import additions, line wrapping for arguments |
| tests/test_cli.py | Trailing comma addition, blank line addition |
| tests/test_capability_tokens.py | Line wrapping for list comprehensions |
| tests/test_audit_verify.py | Dictionary formatting improvements, line wrapping |
| tests/test_audit_export.py | Import reordering, extensive line wrapping and formatting |
| tests/test_article_12_records.py | Line wrapping for function calls |
| tests/test_append_only_store.py | Import order, blank line additions, line wrapping |
| tests/test_api_additional.py | Dictionary formatting, line wrapping |
| tests/test_api.py | Dictionary formatting consistency |
| src/lexecon/tools/audit_verify.py | Blank line after exception class, line wrapping |
| src/lexecon/storage/persistence.py | Extensive SQL query formatting with multi-line strings |
| src/lexecon/security/signature_service.py | Import reordering, line wrapping for cryptography calls |
| src/lexecon/security/middleware.py | Import reordering, line wrapping, blank line additions |
| src/lexecon/security/auth_service.py | Extensive formatting of SQL queries and long conditionals |
| src/lexecon/security/audit_service.py | Import reordering, SQL formatting, line wrapping |
| src/lexecon/risk/service.py | Import order, line wrapping for function calls |
| src/lexecon/responsibility/tracker.py | Import order correction, line wrapping, blank line additions |
| src/lexecon/responsibility/storage.py | Import order, extensive SQL formatting |
| src/lexecon/responsibility/init.py | Import statement consolidation |
| src/lexecon/override/service.py | Import reordering, line wrapping |
| src/lexecon/identity/signing.py | Blank line addition after import |
| src/lexecon/evidence/service.py | Import order correction, line wrapping |
| src/lexecon/evidence/append_only_store.py | Blank line after exception, line wrapping |
| src/lexecon/escalation/service.py | Import reordering, line wrapping |
| src/lexecon/decision/service.py | Import organization with comment preservation |
| src/lexecon/compliance_mapping/service.py | Import reordering, extensive line wrapping and blank line additions |
| src/lexecon/compliance/eu_ai_act/storage.py | SQL query formatting |
| src/lexecon/compliance/eu_ai_act/article_14_oversight.py | Import order, extensive dictionary and line wrapping |
| src/lexecon/compliance/eu_ai_act/article_12_records.py | Import order, extensive formatting improvements |
| src/lexecon/compliance/eu_ai_act/article_11_technical_docs.py | Import order, extensive dictionary formatting |
| src/lexecon/audit_export/service.py | Import reordering, extensive line wrapping and formatting |
Comments suppressed due to low confidence (1)
src/lexecon/evidence/append_only_store.py:88
- This method raises AppendOnlyViolationError - should raise a LookupError (KeyError or IndexError) instead.
def __delitem__(self, key: str):
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lexicoding <234111021+Lexicoding-systems@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lexicoding <234111021+Lexicoding-systems@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lexicoding <234111021+Lexicoding-systems@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lexicoding <234111021+Lexicoding-systems@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Lexicoding <234111021+Lexicoding-systems@users.noreply.github.com>
The CI format-check job was failing with 46 files requiring Black reformatting and 30 files with incorrect import sorting.
Changes
src/andtests/directories (46 files reformatted)pyproject.tomlconfiguration (line-length: 100, isort profile: black)No functional changes—purely cosmetic formatting to satisfy linter requirements.
Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.