fix: clean mypy errors in schemas, models, auth, exceptions layers
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Has been cancelled
CLI Tests / test-cli (push) Has been cancelled
Coverage Phase 1 (70% Target) / test-coverage-70 (push) Has been cancelled
Coverage Phase 2 (85% Target) / test-coverage-85 (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Package Tests / Python package - aitbc-agent-sdk (push) Has been cancelled
Package Tests / Python package - aitbc-core (push) Has been cancelled
Package Tests / Python package - aitbc-crypto (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Has been cancelled
Package Tests / JavaScript package - aitbc-sdk-js (push) Has been cancelled
Package Tests / JavaScript package - aitbc-token (push) Has been cancelled
Production Tests / Production Integration Tests (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Has been cancelled
CLI Tests / test-cli (push) Has been cancelled
Coverage Phase 1 (70% Target) / test-coverage-70 (push) Has been cancelled
Coverage Phase 2 (85% Target) / test-coverage-85 (push) Has been cancelled
Cross-Node Transaction Testing / transaction-test (push) Has been cancelled
Deploy to Testnet / deploy-testnet (push) Has been cancelled
Integration Tests / test-service-integration (push) Has been cancelled
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Package Tests / Python package - aitbc-agent-sdk (push) Has been cancelled
Package Tests / Python package - aitbc-core (push) Has been cancelled
Package Tests / Python package - aitbc-crypto (push) Has been cancelled
Package Tests / Python package - aitbc-sdk (push) Has been cancelled
Package Tests / JavaScript package - aitbc-sdk-js (push) Has been cancelled
Package Tests / JavaScript package - aitbc-token (push) Has been cancelled
Production Tests / Production Integration Tests (push) Has been cancelled
Python Tests / test-python (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
schemas/ — 0 errors (11 files): - federated_learning, decentralized_memory, dao_governance, atomic_swap: fix self-imports to import enums from domain layer - pricing.py: add timezone import, fix default_factory lambda, annotate validator - __init__.py: remove invalid ser_json_tuples from ConfigDict models/ — 0 errors (10 files): - registry.py: add timezone import, fix default_factory lambda, annotate validator, add items field to ParameterDefinition (used at callsites) - services.py: annotate validators with proper types, use ValidationInfo, fix no-any-return with explicit typed local - confidential.py: rename metadata->extra_metadata (conflicts with SQLModel), add mypy disable for pydantic-field (raw SQLAlchemy Column pattern) auth.py: add -> str return type exceptions.py: fix Optional param defaults to use X | None annotations pyproject.toml: - Add pydantic.mypy plugin (fixes false Pydantic v2 positive errors) - Remove models.* from ignore_errors override (layer now clean) - Update clean-layer comment 51 source files now pass mypy with no errors. Remaining ignore_errors: routers, services, storage, utils, contexts (coordinator-api) and all blanket-suppressed apps.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
def get_api_key():
|
||||
def get_api_key() -> str:
|
||||
return "test-key"
|
||||
|
||||
@@ -102,7 +102,7 @@ class APIError(AITBCError):
|
||||
error_code: str = "API_ERROR"
|
||||
status_code: int = 500
|
||||
|
||||
def __init__(self, message: str, status_code: int = None, response: dict = None):
|
||||
def __init__(self, message: str, status_code: int | None = None, response: dict[str, object] | None = None):
|
||||
super().__init__(message)
|
||||
self.status_code = status_code or self.status_code
|
||||
self.response = response
|
||||
@@ -144,7 +144,7 @@ class ValidationError(AITBCError):
|
||||
error_code: str = "VALIDATION_ERROR"
|
||||
status_code: int = 422
|
||||
|
||||
def __init__(self, message: str = "Validation failed", details: list[ErrorDetail] = None):
|
||||
def __init__(self, message: str = "Validation failed", details: list[ErrorDetail] | None = None):
|
||||
super().__init__(message)
|
||||
self.details = details or []
|
||||
|
||||
@@ -216,7 +216,7 @@ class QuotaExceededError(ConnectorError):
|
||||
error_code: str = "QUOTA_EXCEEDED"
|
||||
status_code: int = 429
|
||||
|
||||
def __init__(self, message: str = "Quota exceeded", limit: int = None):
|
||||
def __init__(self, message: str = "Quota exceeded", limit: int | None = None):
|
||||
super().__init__(message)
|
||||
self.limit = limit
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Database models for confidential transactions
|
||||
"""
|
||||
# mypy: disable-error-code="pydantic-field"
|
||||
|
||||
import uuid
|
||||
|
||||
@@ -152,7 +153,7 @@ class AuditAuthorizationDB(Base):
|
||||
|
||||
# Authorization data
|
||||
signature = Column(String(512), nullable=False)
|
||||
metadata = Column(JSON, nullable=True)
|
||||
extra_metadata = Column(JSON, nullable=True)
|
||||
|
||||
# Status
|
||||
active = Column(Boolean, nullable=False, default=True)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Dynamic service registry models for AITBC
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
|
||||
@@ -56,6 +56,7 @@ class ParameterDefinition(BaseModel):
|
||||
max_value: int | float | None = Field(None, description="Maximum value")
|
||||
options: list[str | int] | None = Field(None, description="Available options for enum type")
|
||||
validation: dict[str, Any] | None = Field(None, description="Custom validation rules")
|
||||
items: dict[str, Any] | None = Field(None, description="Schema for array item type")
|
||||
|
||||
|
||||
class HardwareRequirement(BaseModel):
|
||||
@@ -112,7 +113,7 @@ class ServiceDefinition(BaseModel):
|
||||
example_usage: dict[str, Any] | None = Field(None, description="Example usage")
|
||||
|
||||
@validator("id")
|
||||
def validate_id(cls, v):
|
||||
def validate_id(cls, v: str) -> str:
|
||||
if not v or not v.replace("_", "").replace("-", "").isalnum():
|
||||
raise ValueError("Service ID must contain only alphanumeric characters, hyphens, and underscores")
|
||||
return v.lower()
|
||||
@@ -122,7 +123,7 @@ class ServiceRegistry(BaseModel):
|
||||
"""Service registry containing all available services"""
|
||||
|
||||
version: str = Field("1.0.0", description="Registry version")
|
||||
last_updated: datetime = Field(default_factory=datetime.now(timezone.utc), description="Last update time")
|
||||
last_updated: datetime = Field(default_factory=lambda: datetime.now(timezone.utc), description="Last update time")
|
||||
services: dict[str, ServiceDefinition] = Field(..., description="Service definitions by ID")
|
||||
|
||||
def get_service(self, service_id: str) -> ServiceDefinition | None:
|
||||
|
||||
@@ -5,7 +5,7 @@ Service schemas for common GPU workloads
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from pydantic import BaseModel, Field, ValidationInfo, field_validator
|
||||
|
||||
|
||||
class ServiceType(StrEnum):
|
||||
@@ -133,7 +133,7 @@ class StableDiffusionRequest(BaseModel):
|
||||
|
||||
@field_validator("seed")
|
||||
@classmethod
|
||||
def validate_seed(cls, v):
|
||||
def validate_seed(cls, v: int | list[int] | None) -> int | list[int] | None:
|
||||
if v is not None and isinstance(v, list):
|
||||
if len(v) > 4:
|
||||
raise ValueError("Maximum 4 seeds allowed")
|
||||
@@ -308,7 +308,7 @@ class BlenderRequest(BaseModel):
|
||||
|
||||
@field_validator("frame_end")
|
||||
@classmethod
|
||||
def validate_frame_range(cls, v, info):
|
||||
def validate_frame_range(cls, v: int, info: ValidationInfo) -> int:
|
||||
if info and info.data and "frame_start" in info.data and v < info.data["frame_start"]:
|
||||
raise ValueError("frame_end must be >= frame_start")
|
||||
return v
|
||||
@@ -346,7 +346,8 @@ class ServiceRequest(BaseModel):
|
||||
}
|
||||
|
||||
service_class = service_classes[self.service_type]
|
||||
return service_class(**self.request_data)
|
||||
result: WhisperRequest | StableDiffusionRequest | LLMRequest | FFmpegRequest | BlenderRequest = service_class(**self.request_data)
|
||||
return result
|
||||
|
||||
|
||||
# Service Response Schemas
|
||||
|
||||
@@ -395,7 +395,7 @@ class BlockListResponse(BaseModel):
|
||||
|
||||
|
||||
class TransactionSummary(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True, ser_json_tuples=True)
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
hash: str
|
||||
block: str | int
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .atomic_swap import SwapStatus
|
||||
from ..domain.atomic_swap import SwapStatus
|
||||
|
||||
|
||||
class SwapCreateRequest(BaseModel):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from .dao_governance import ProposalType
|
||||
from ..domain.dao_governance import ProposalType
|
||||
|
||||
|
||||
class MemberCreate(BaseModel):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from .decentralized_memory import MemoryType, StorageStatus
|
||||
from ..domain.decentralized_memory import MemoryType, StorageStatus
|
||||
|
||||
|
||||
class MemoryNodeCreate(BaseModel):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .federated_learning import TrainingStatus
|
||||
from ..domain.federated_learning import TrainingStatus
|
||||
|
||||
|
||||
class FederatedSessionCreate(BaseModel):
|
||||
|
||||
@@ -3,7 +3,7 @@ Pricing API Schemas
|
||||
Pydantic models for dynamic pricing API requests and responses
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from enum import StrEnum
|
||||
from typing import Any
|
||||
|
||||
@@ -64,7 +64,7 @@ class PricingStrategyRequest(BaseModel):
|
||||
regions: list[str] | None = Field(None, description="Applicable regions")
|
||||
|
||||
@validator("constraints")
|
||||
def validate_constraints(cls, v):
|
||||
def validate_constraints(cls, v: dict[str, Any] | None) -> dict[str, Any] | None:
|
||||
if v is not None:
|
||||
# Validate constraint fields
|
||||
if "min_price" in v and v["min_price"] is not None and v["min_price"] <= 0:
|
||||
@@ -358,7 +358,7 @@ class PricingError(BaseModel):
|
||||
error_code: str = Field(..., description="Error code")
|
||||
message: str = Field(..., description="Error message")
|
||||
details: dict[str, Any] | None = Field(None, description="Additional error details")
|
||||
timestamp: datetime = Field(default_factory=datetime.now(timezone.utc), description="Error timestamp")
|
||||
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc), description="Error timestamp")
|
||||
|
||||
class Config:
|
||||
json_encoders = {datetime: lambda v: v.isoformat()}
|
||||
|
||||
Reference in New Issue
Block a user