Fix mypy type checking errors
- Updated mypy configuration to use Python 3.9+ - Added missing type annotations to all function parameters - Fixed type compatibility issues in variable assignments - Resolved unreachable code and return type warnings - All mypy checks now pass successfully 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,10 @@ class WikiJSClient:
|
||||
verify_ssl: bool = True,
|
||||
user_agent: Optional[str] = None,
|
||||
):
|
||||
# Instance variable declarations for mypy
|
||||
self._auth_handler: AuthHandler
|
||||
self._session: requests.Session
|
||||
|
||||
# Validate and normalize base URL
|
||||
self.base_url = normalize_url(base_url)
|
||||
|
||||
@@ -140,7 +144,7 @@ class WikiJSClient:
|
||||
endpoint: str,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
json_data: Optional[Dict[str, Any]] = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Dict[str, Any]:
|
||||
"""Make HTTP request to Wiki.js API.
|
||||
|
||||
@@ -258,15 +262,15 @@ class WikiJSClient:
|
||||
except Exception as e:
|
||||
raise ConnectionError(f"Connection test failed: {str(e)}")
|
||||
|
||||
def __enter__(self):
|
||||
def __enter__(self) -> "WikiJSClient":
|
||||
"""Context manager entry."""
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
||||
"""Context manager exit - close session."""
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""Close the HTTP session and clean up resources."""
|
||||
if self._session:
|
||||
self._session.close()
|
||||
|
||||
@@ -30,7 +30,7 @@ class BaseEndpoint:
|
||||
endpoint: str,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
json_data: Optional[Dict[str, Any]] = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Dict[str, Any]:
|
||||
"""Make HTTP request through the client.
|
||||
|
||||
@@ -53,7 +53,7 @@ class BaseEndpoint:
|
||||
)
|
||||
|
||||
def _get(
|
||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs
|
||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
"""Make GET request.
|
||||
|
||||
@@ -72,7 +72,7 @@ class BaseEndpoint:
|
||||
endpoint: str,
|
||||
json_data: Optional[Dict[str, Any]] = None,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Dict[str, Any]:
|
||||
"""Make POST request.
|
||||
|
||||
@@ -94,7 +94,7 @@ class BaseEndpoint:
|
||||
endpoint: str,
|
||||
json_data: Optional[Dict[str, Any]] = None,
|
||||
params: Optional[Dict[str, Any]] = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Dict[str, Any]:
|
||||
"""Make PUT request.
|
||||
|
||||
@@ -112,7 +112,7 @@ class BaseEndpoint:
|
||||
)
|
||||
|
||||
def _delete(
|
||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs
|
||||
self, endpoint: str, params: Optional[Dict[str, Any]] = None, **kwargs: Any
|
||||
) -> Dict[str, Any]:
|
||||
"""Make DELETE request.
|
||||
|
||||
|
||||
@@ -411,7 +411,7 @@ class PagesEndpoint(BaseEndpoint):
|
||||
"""
|
||||
|
||||
# Build variables (only include non-None values)
|
||||
variables = {"id": page_id}
|
||||
variables: Dict[str, Any] = {"id": page_id}
|
||||
|
||||
if page_data.title is not None:
|
||||
variables["title"] = page_data.title
|
||||
|
||||
@@ -63,7 +63,7 @@ class PermissionError(ClientError):
|
||||
class RateLimitError(ClientError):
|
||||
"""Raised when rate limit is exceeded (429)."""
|
||||
|
||||
def __init__(self, message: str, retry_after: Optional[int] = None, **kwargs):
|
||||
def __init__(self, message: str, retry_after: Optional[int] = None, **kwargs: Any) -> None:
|
||||
# Remove status_code from kwargs if present to avoid duplicate argument
|
||||
kwargs.pop("status_code", None)
|
||||
super().__init__(message, status_code=429, **kwargs)
|
||||
|
||||
@@ -38,7 +38,7 @@ class Page(TimestampedModel):
|
||||
editor: Optional[str] = Field(None, description="Editor used")
|
||||
|
||||
@validator("path")
|
||||
def validate_path(cls, v):
|
||||
def validate_path(cls, v: str) -> str:
|
||||
"""Validate page path format."""
|
||||
if not v:
|
||||
raise ValueError("Path cannot be empty")
|
||||
@@ -53,7 +53,7 @@ class Page(TimestampedModel):
|
||||
return v
|
||||
|
||||
@validator("title")
|
||||
def validate_title(cls, v):
|
||||
def validate_title(cls, v: str) -> str:
|
||||
"""Validate page title."""
|
||||
if not v or not v.strip():
|
||||
raise ValueError("Title cannot be empty")
|
||||
@@ -133,7 +133,7 @@ class PageCreate(BaseModel):
|
||||
editor: str = Field("markdown", description="Editor to use")
|
||||
|
||||
@validator("path")
|
||||
def validate_path(cls, v):
|
||||
def validate_path(cls, v: str) -> str:
|
||||
"""Validate page path format."""
|
||||
if not v:
|
||||
raise ValueError("Path cannot be empty")
|
||||
@@ -148,7 +148,7 @@ class PageCreate(BaseModel):
|
||||
return v
|
||||
|
||||
@validator("title")
|
||||
def validate_title(cls, v):
|
||||
def validate_title(cls, v: str) -> str:
|
||||
"""Validate page title."""
|
||||
if not v or not v.strip():
|
||||
raise ValueError("Title cannot be empty")
|
||||
@@ -173,7 +173,7 @@ class PageUpdate(BaseModel):
|
||||
tags: Optional[List[str]] = Field(None, description="Page tags")
|
||||
|
||||
@validator("title")
|
||||
def validate_title(cls, v):
|
||||
def validate_title(cls, v: Optional[str]) -> Optional[str]:
|
||||
"""Validate page title if provided."""
|
||||
if v is not None:
|
||||
if not v.strip():
|
||||
|
||||
@@ -103,7 +103,7 @@ def build_api_url(base_url: str, endpoint: str) -> str:
|
||||
return urljoin(api_base, endpoint.lstrip("/"))
|
||||
|
||||
|
||||
def parse_wiki_response(response_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
def parse_wiki_response(response_data: Any) -> Dict[str, Any]:
|
||||
"""Parse Wiki.js API response data.
|
||||
|
||||
Args:
|
||||
@@ -116,7 +116,7 @@ def parse_wiki_response(response_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
APIError: If response indicates an error
|
||||
"""
|
||||
if not isinstance(response_data, dict):
|
||||
return response_data
|
||||
return {"data": response_data}
|
||||
|
||||
# Check for error indicators
|
||||
if "error" in response_data:
|
||||
@@ -166,9 +166,8 @@ def extract_error_message(response: Any) -> str:
|
||||
pass
|
||||
|
||||
if hasattr(response, "text"):
|
||||
return (
|
||||
response.text[:200] + "..." if len(response.text) > 200 else response.text
|
||||
)
|
||||
text = str(response.text)
|
||||
return text[:200] + "..." if len(text) > 200 else text
|
||||
|
||||
return str(response)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user