Fix import ordering for isort compliance#10
Conversation
Co-authored-by: pangerlkr <73515951+pangerlkr@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR attempts to fix import ordering to comply with isort checks in the CI/CD pipeline, but the import ordering is incorrect. The PR adds pyproject.toml configuration for black and isort, reorders imports in gateway/main_production.py, and reformats some long lines to fit within the 127-character limit.
Changes:
- Added pyproject.toml with black and isort configuration (line length 127, isort profile "black")
- Incorrectly reordered imports in gateway/main_production.py by placing local modules before third-party imports (opposite of PEP 8 requirements)
- Reformatted multi-line statements to single lines in gateway/main_production.py and gateway/database.py
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pyproject.toml | Adds black and isort configuration with line length 127 and compatibility settings |
| gateway/main_production.py | Incorrectly reorders imports (places local before third-party instead of after), and reformats long lines |
| gateway/database.py | Reformats sessionmaker initialization from multi-line to single line |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -14,9 +16,6 @@ | |||
| from slowapi.errors import RateLimitExceeded | |||
| from slowapi.util import get_remote_address | |||
There was a problem hiding this comment.
The import ordering is incorrect according to PEP 8 and isort standards. Per PEP 8, imports should be grouped in this order: (1) standard library, (2) third-party, (3) local application imports.
Currently, local imports (config, database) are placed before third-party imports (fastapi, pydantic, slowapi, etc.). They should be placed after all third-party imports, with a blank line separating the groups. The correct order should be:
import redis
from fastapi import FastAPI, HTTPException, Request, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field, validator
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.util import get_remote_address
from config import get_settings
from database import DatabaseManager, IOCRecord, ReconTask
| from config import get_settings | ||
| from database import DatabaseManager, IOCRecord, ReconTask |
There was a problem hiding this comment.
The PR description incorrectly states that local modules should be placed "before third-party imports per PEP 8 import grouping." This is backwards - PEP 8 actually requires local application imports to come AFTER third-party imports, not before. The correct order per PEP 8 is: (1) standard library, (2) third-party, (3) local. This discrepancy between the description and the actual PEP 8 standard suggests a misunderstanding of the import ordering rules.
The CI/CD pipeline was failing on
isortchecks due to incorrect import ordering in gateway files.Changes
config,database) before third-party imports (FastAPI, pydantic, etc.) per PEP 8 import groupingblackandisortcompatibility with consistent line length (127) and import formatting