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: fix linting errors #7541

Merged
merged 2 commits into from
Apr 12, 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
3 changes: 2 additions & 1 deletion haystack/lazy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __init__(self, message: str = DEFAULT_IMPORT_ERROR_MSG) -> None:
def __exit__(
self, exc_type: Optional[Type[Exception]], exc_value: Optional[Exception], traceback: Optional[TracebackType]
) -> Optional[bool]:
"""Exit the context manager.
"""
Exit the context manager.

Args:
exc_type:
Expand Down
3 changes: 3 additions & 0 deletions haystack/marshal/protocol.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# pylint: disable=unnecessary-ellipsis
from typing import Any, Dict, Protocol, Union


class Marshaller(Protocol):
def marshal(self, dict_: Dict[str, Any]) -> str:
"Convert a dictionary to its string representation"
...

def unmarshal(self, data_: Union[str, bytes, bytearray]) -> Dict[str, Any]:
"""Convert a marshalled object to its dictionary representation"""
...
3 changes: 2 additions & 1 deletion haystack/tracing/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def get_correlation_data_for_logs(self) -> Dict[str, Any]:
"""
Return a dictionary with correlation data for logs.

This is useful if you want to correlate logs with traces."""
This is useful if you want to correlate logs with traces.
"""
return {}


Expand Down
16 changes: 8 additions & 8 deletions haystack/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def from_str(string: str) -> "SecretType":
:param string: The string to convert.
"""
mapping = {e.value: e for e in SecretType}
type = mapping.get(string)
if type is None:
_type = mapping.get(string)
if _type is None:
raise ValueError(f"Unknown secret type '{string}'")
return type
return _type


class Secret(ABC):
Expand Down Expand Up @@ -83,7 +83,7 @@ def to_dict(self) -> Dict[str, Any]:
return out

@staticmethod
def from_dict(dict: Dict[str, Any]) -> "Secret":
def from_dict(dict: Dict[str, Any]) -> "Secret": # noqa:A002
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These noqa were added to avoid breaking changes

"""
Create a secret from a JSON-serializable dictionary.

Expand Down Expand Up @@ -120,7 +120,7 @@ def _to_dict(self) -> Dict[str, Any]:

@staticmethod
@abstractmethod
def _from_dict(dict: Dict[str, Any]) -> "Secret":
def _from_dict(_: Dict[str, Any]) -> "Secret":
pass


Expand Down Expand Up @@ -148,7 +148,7 @@ def _to_dict(self) -> Dict[str, Any]:
)

@staticmethod
def _from_dict(dict: Dict[str, Any]) -> "Secret":
def _from_dict(_: Dict[str, Any]) -> "Secret":
raise ValueError(
"Cannot deserialize token-based secret. Use an alternative secret type like environment variables."
)
Expand Down Expand Up @@ -186,8 +186,8 @@ def _to_dict(self) -> Dict[str, Any]:
return {"env_vars": list(self._env_vars), "strict": self._strict}

@staticmethod
def _from_dict(dict: Dict[str, Any]) -> "Secret":
return EnvVarSecret(tuple(dict["env_vars"]), _strict=dict["strict"])
def _from_dict(dictionary: Dict[str, Any]) -> "Secret":
return EnvVarSecret(tuple(dictionary["env_vars"]), _strict=dictionary["strict"])

def resolve_value(self) -> Optional[Any]:
"""Resolve the secret to an atomic value. The semantics of the value is secret-dependent."""
Expand Down
16 changes: 8 additions & 8 deletions haystack/utils/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def from_str(string: str) -> "DeviceType":
:returns:
The device type.
"""
map = {e.value: e for e in DeviceType}
type = map.get(string)
if type is None:
mapping = {e.value: e for e in DeviceType}
_type = mapping.get(string)
if _type is None:
raise ValueError(f"Unknown device type string '{string}'")
return type
return _type


@dataclass
Expand All @@ -61,7 +61,7 @@ class Device:
type: DeviceType
id: Optional[int] = field(default=None)

def __init__(self, type: DeviceType, id: Optional[int] = None):
def __init__(self, type: DeviceType, id: Optional[int] = None): # noqa:A002
"""
Create a generic device.

Expand Down Expand Up @@ -93,7 +93,7 @@ def cpu() -> "Device":
return Device(DeviceType.CPU)

@staticmethod
def gpu(id: int = 0) -> "Device":
def gpu(id: int = 0) -> "Device": # noqa:A002
"""
Create a generic GPU device.

Expand Down Expand Up @@ -189,7 +189,7 @@ def first_device(self) -> Optional[Device]:
return next(iter(self.mapping.values()))

@staticmethod
def from_dict(dict: Dict[str, str]) -> "DeviceMap":
def from_dict(dict: Dict[str, str]) -> "DeviceMap": # noqa:A002
"""
Create a generic device map from a JSON-serialized dictionary.

Expand Down Expand Up @@ -458,7 +458,7 @@ def to_dict(self) -> Dict[str, Any]:
assert False

@classmethod
def from_dict(cls, dict: Dict[str, Any]) -> "ComponentDevice":
def from_dict(cls, dict: Dict[str, Any]) -> "ComponentDevice": # noqa:A002
"""
Create a component device representation from a JSON-serialized dictionary.

Expand Down