Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove self type annotations #311

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/apify_client/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ApifyApiError(ApifyClientError):
"""

@ignore_docs
def __init__(self: ApifyApiError, response: httpx.Response, attempt: int) -> None:
def __init__(self, response: httpx.Response, attempt: int) -> None:
"""Create the ApifyApiError instance.

Args:
Expand Down Expand Up @@ -59,7 +59,7 @@ class InvalidResponseBodyError(ApifyClientError):
"""

@ignore_docs
def __init__(self: InvalidResponseBodyError, response: httpx.Response) -> None:
def __init__(self, response: httpx.Response) -> None:
"""Create the InvalidResponseBodyError instance.

Args:
Expand Down
8 changes: 4 additions & 4 deletions src/apify_client/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class _BaseHTTPClient:
@ignore_docs
def __init__(
self: _BaseHTTPClient,
self,
*,
token: str | None = None,
max_retries: int = 8,
Expand Down Expand Up @@ -97,7 +97,7 @@ def _parse_params(params: dict | None) -> dict | None:
return parsed_params

def _prepare_request_call(
self: _BaseHTTPClient,
self,
headers: dict | None = None,
params: dict | None = None,
data: Any = None,
Expand Down Expand Up @@ -129,7 +129,7 @@ def _prepare_request_call(

class HTTPClient(_BaseHTTPClient):
def call(
self: HTTPClient,
self,
*,
method: str,
url: str,
Expand Down Expand Up @@ -201,7 +201,7 @@ def _make_request(stop_retrying: Callable, attempt: int) -> httpx.Response:

class HTTPClientAsync(_BaseHTTPClient):
async def call(
self: HTTPClientAsync,
self,
*,
method: str,
url: str,
Expand Down
12 changes: 6 additions & 6 deletions src/apify_client/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import logging
from contextvars import ContextVar
from typing import TYPE_CHECKING, Any, Callable, NamedTuple, cast
from typing import TYPE_CHECKING, Any, Callable, NamedTuple

# Conditional import only executed when type checking, otherwise we'd get circular dependency issues
if TYPE_CHECKING:
Expand Down Expand Up @@ -39,12 +39,12 @@ class LogContext(NamedTuple):
# Metaclass for resource clients which wraps all their public methods
# With injection of their details to the log context vars
class WithLogDetailsClient(type):
def __new__(cls: type[type], name: str, bases: tuple, attrs: dict) -> WithLogDetailsClient:
def __new__(cls, name: str, bases: tuple, attrs: dict) -> WithLogDetailsClient:
for attr_name, attr_value in attrs.items():
if not attr_name.startswith('_') and inspect.isfunction(attr_value):
attrs[attr_name] = _injects_client_details_to_log_context(attr_value)

return cast(WithLogDetailsClient, type.__new__(cls, name, bases, attrs))
return type.__new__(cls, name, bases, attrs)


# Wraps an unbound method so that its call will inject the details
Expand Down Expand Up @@ -87,7 +87,7 @@ def wrapper(resource_client: _BaseBaseClient, *args: Any, **kwargs: Any) -> Any:
# A filter which lets every log record through,
# but adds the current logging context to the record
class _ContextInjectingFilter(logging.Filter):
def filter(self: _ContextInjectingFilter, record: logging.LogRecord) -> bool:
def filter(self, record: logging.LogRecord) -> bool:
record.client_method = log_context.client_method.get()
record.resource_id = log_context.resource_id.get()
record.method = log_context.method.get()
Expand All @@ -105,15 +105,15 @@ class _DebugLogFormatter(logging.Formatter):
empty_record = logging.LogRecord('dummy', 0, 'dummy', 0, 'dummy', None, None)

# Gets the extra fields from the log record which are not present on an empty record
def _get_extra_fields(self: _DebugLogFormatter, record: logging.LogRecord) -> dict:
def _get_extra_fields(self, record: logging.LogRecord) -> dict:
extra_fields: dict = {}
for key, value in record.__dict__.items():
if key not in self.empty_record.__dict__:
extra_fields[key] = value # noqa: PERF403

return extra_fields

def format(self: _DebugLogFormatter, record: logging.LogRecord) -> str:
def format(self, record: logging.LogRecord) -> str:
extra = self._get_extra_fields(record)

log_string = super().format(record)
Expand Down
Loading
Loading