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:
@@ -94,7 +94,7 @@ known_first_party = ["wikijs"]
|
|||||||
known_third_party = ["pytest", "requests", "pydantic"]
|
known_third_party = ["pytest", "requests", "pydantic"]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
python_version = "3.8"
|
python_version = "3.9"
|
||||||
warn_return_any = true
|
warn_return_any = true
|
||||||
warn_unused_configs = true
|
warn_unused_configs = true
|
||||||
disallow_untyped_defs = true
|
disallow_untyped_defs = true
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ class WikiJSClient:
|
|||||||
verify_ssl: bool = True,
|
verify_ssl: bool = True,
|
||||||
user_agent: Optional[str] = None,
|
user_agent: Optional[str] = None,
|
||||||
):
|
):
|
||||||
|
# Instance variable declarations for mypy
|
||||||
|
self._auth_handler: AuthHandler
|
||||||
|
self._session: requests.Session
|
||||||
|
|
||||||
# Validate and normalize base URL
|
# Validate and normalize base URL
|
||||||
self.base_url = normalize_url(base_url)
|
self.base_url = normalize_url(base_url)
|
||||||
|
|
||||||
@@ -140,7 +144,7 @@ class WikiJSClient:
|
|||||||
endpoint: str,
|
endpoint: str,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Make HTTP request to Wiki.js API.
|
"""Make HTTP request to Wiki.js API.
|
||||||
|
|
||||||
@@ -258,15 +262,15 @@ class WikiJSClient:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ConnectionError(f"Connection test failed: {str(e)}")
|
raise ConnectionError(f"Connection test failed: {str(e)}")
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self) -> "WikiJSClient":
|
||||||
"""Context manager entry."""
|
"""Context manager entry."""
|
||||||
return self
|
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."""
|
"""Context manager exit - close session."""
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def close(self):
|
def close(self) -> None:
|
||||||
"""Close the HTTP session and clean up resources."""
|
"""Close the HTTP session and clean up resources."""
|
||||||
if self._session:
|
if self._session:
|
||||||
self._session.close()
|
self._session.close()
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class BaseEndpoint:
|
|||||||
endpoint: str,
|
endpoint: str,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Make HTTP request through the client.
|
"""Make HTTP request through the client.
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ class BaseEndpoint:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _get(
|
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]:
|
) -> Dict[str, Any]:
|
||||||
"""Make GET request.
|
"""Make GET request.
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ class BaseEndpoint:
|
|||||||
endpoint: str,
|
endpoint: str,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Make POST request.
|
"""Make POST request.
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ class BaseEndpoint:
|
|||||||
endpoint: str,
|
endpoint: str,
|
||||||
json_data: Optional[Dict[str, Any]] = None,
|
json_data: Optional[Dict[str, Any]] = None,
|
||||||
params: Optional[Dict[str, Any]] = None,
|
params: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""Make PUT request.
|
"""Make PUT request.
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class BaseEndpoint:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _delete(
|
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]:
|
) -> Dict[str, Any]:
|
||||||
"""Make DELETE request.
|
"""Make DELETE request.
|
||||||
|
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Build variables (only include non-None values)
|
# 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:
|
if page_data.title is not None:
|
||||||
variables["title"] = page_data.title
|
variables["title"] = page_data.title
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class PermissionError(ClientError):
|
|||||||
class RateLimitError(ClientError):
|
class RateLimitError(ClientError):
|
||||||
"""Raised when rate limit is exceeded (429)."""
|
"""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
|
# Remove status_code from kwargs if present to avoid duplicate argument
|
||||||
kwargs.pop("status_code", None)
|
kwargs.pop("status_code", None)
|
||||||
super().__init__(message, status_code=429, **kwargs)
|
super().__init__(message, status_code=429, **kwargs)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class Page(TimestampedModel):
|
|||||||
editor: Optional[str] = Field(None, description="Editor used")
|
editor: Optional[str] = Field(None, description="Editor used")
|
||||||
|
|
||||||
@validator("path")
|
@validator("path")
|
||||||
def validate_path(cls, v):
|
def validate_path(cls, v: str) -> str:
|
||||||
"""Validate page path format."""
|
"""Validate page path format."""
|
||||||
if not v:
|
if not v:
|
||||||
raise ValueError("Path cannot be empty")
|
raise ValueError("Path cannot be empty")
|
||||||
@@ -53,7 +53,7 @@ class Page(TimestampedModel):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
@validator("title")
|
@validator("title")
|
||||||
def validate_title(cls, v):
|
def validate_title(cls, v: str) -> str:
|
||||||
"""Validate page title."""
|
"""Validate page title."""
|
||||||
if not v or not v.strip():
|
if not v or not v.strip():
|
||||||
raise ValueError("Title cannot be empty")
|
raise ValueError("Title cannot be empty")
|
||||||
@@ -133,7 +133,7 @@ class PageCreate(BaseModel):
|
|||||||
editor: str = Field("markdown", description="Editor to use")
|
editor: str = Field("markdown", description="Editor to use")
|
||||||
|
|
||||||
@validator("path")
|
@validator("path")
|
||||||
def validate_path(cls, v):
|
def validate_path(cls, v: str) -> str:
|
||||||
"""Validate page path format."""
|
"""Validate page path format."""
|
||||||
if not v:
|
if not v:
|
||||||
raise ValueError("Path cannot be empty")
|
raise ValueError("Path cannot be empty")
|
||||||
@@ -148,7 +148,7 @@ class PageCreate(BaseModel):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
@validator("title")
|
@validator("title")
|
||||||
def validate_title(cls, v):
|
def validate_title(cls, v: str) -> str:
|
||||||
"""Validate page title."""
|
"""Validate page title."""
|
||||||
if not v or not v.strip():
|
if not v or not v.strip():
|
||||||
raise ValueError("Title cannot be empty")
|
raise ValueError("Title cannot be empty")
|
||||||
@@ -173,7 +173,7 @@ class PageUpdate(BaseModel):
|
|||||||
tags: Optional[List[str]] = Field(None, description="Page tags")
|
tags: Optional[List[str]] = Field(None, description="Page tags")
|
||||||
|
|
||||||
@validator("title")
|
@validator("title")
|
||||||
def validate_title(cls, v):
|
def validate_title(cls, v: Optional[str]) -> Optional[str]:
|
||||||
"""Validate page title if provided."""
|
"""Validate page title if provided."""
|
||||||
if v is not None:
|
if v is not None:
|
||||||
if not v.strip():
|
if not v.strip():
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ def build_api_url(base_url: str, endpoint: str) -> str:
|
|||||||
return urljoin(api_base, endpoint.lstrip("/"))
|
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.
|
"""Parse Wiki.js API response data.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -116,7 +116,7 @@ def parse_wiki_response(response_data: Dict[str, Any]) -> Dict[str, Any]:
|
|||||||
APIError: If response indicates an error
|
APIError: If response indicates an error
|
||||||
"""
|
"""
|
||||||
if not isinstance(response_data, dict):
|
if not isinstance(response_data, dict):
|
||||||
return response_data
|
return {"data": response_data}
|
||||||
|
|
||||||
# Check for error indicators
|
# Check for error indicators
|
||||||
if "error" in response_data:
|
if "error" in response_data:
|
||||||
@@ -166,9 +166,8 @@ def extract_error_message(response: Any) -> str:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if hasattr(response, "text"):
|
if hasattr(response, "text"):
|
||||||
return (
|
text = str(response.text)
|
||||||
response.text[:200] + "..." if len(response.text) > 200 else response.text
|
return text[:200] + "..." if len(text) > 200 else text
|
||||||
)
|
|
||||||
|
|
||||||
return str(response)
|
return str(response)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user