diff --git a/pyproject.toml b/pyproject.toml index 3579015..43f781b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,7 +94,7 @@ known_first_party = ["wikijs"] known_third_party = ["pytest", "requests", "pydantic"] [tool.mypy] -python_version = "3.8" +python_version = "3.9" warn_return_any = true warn_unused_configs = true disallow_untyped_defs = true diff --git a/wikijs/client.py b/wikijs/client.py index 64067ba..3357767 100644 --- a/wikijs/client.py +++ b/wikijs/client.py @@ -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() diff --git a/wikijs/endpoints/base.py b/wikijs/endpoints/base.py index 8d1a2ac..0887ff7 100644 --- a/wikijs/endpoints/base.py +++ b/wikijs/endpoints/base.py @@ -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. diff --git a/wikijs/endpoints/pages.py b/wikijs/endpoints/pages.py index 97633ac..1fa9940 100644 --- a/wikijs/endpoints/pages.py +++ b/wikijs/endpoints/pages.py @@ -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 diff --git a/wikijs/exceptions.py b/wikijs/exceptions.py index c1916f1..b6c4179 100644 --- a/wikijs/exceptions.py +++ b/wikijs/exceptions.py @@ -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) diff --git a/wikijs/models/page.py b/wikijs/models/page.py index 8454294..493e782 100644 --- a/wikijs/models/page.py +++ b/wikijs/models/page.py @@ -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(): diff --git a/wikijs/utils/helpers.py b/wikijs/utils/helpers.py index 7dea768..5a3af4c 100644 --- a/wikijs/utils/helpers.py +++ b/wikijs/utils/helpers.py @@ -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)