|
1 | 1 | from collections.abc import Callable |
2 | | -from typing import Any |
3 | 2 | from functools import partial |
| 3 | +from typing import Any |
4 | 4 |
|
5 | 5 | from mastermind.storage.pickle_io import ( |
6 | 6 | delete_pickled_data, |
@@ -62,26 +62,22 @@ def _modify_item(self, key: str, value: Any) -> None: |
62 | 62 | self._data[key] = value |
63 | 63 | self.save_data() |
64 | 64 |
|
| 65 | + def __contains__(self, key: str) -> bool: |
| 66 | + return key in self._data |
| 67 | + |
| 68 | + # Allow dot and bracket notation for accessing and modifying data |
65 | 69 | def __getattr__(self, key: str) -> Any: |
66 | | - """Retrieves the value associated with the given key.""" |
67 | 70 | return self._retrieve_item(key) |
68 | 71 |
|
69 | 72 | def __getitem__(self, key: str) -> Any: |
70 | | - """Retrieves the value associated with the given key.""" |
71 | 73 | return self._retrieve_item(key) |
72 | 74 |
|
73 | 75 | def __setattr__(self, key: str, value: Any) -> None: |
74 | | - """Modifies the value associated with the given key, and saves the changes.""" |
75 | 76 | self._modify_item(key, value) |
76 | 77 |
|
77 | 78 | def __setitem__(self, key: str, value: Any) -> None: |
78 | | - """Modifies the value associated with the given key, and saves the changes.""" |
79 | 79 | self._modify_item(key, value) |
80 | 80 |
|
81 | | - def __contains__(self, key: str) -> bool: |
82 | | - """Checks if the given key exists in the user data.""" |
83 | | - return key in self._data |
84 | | - |
85 | 81 |
|
86 | 82 | def _load_data_safely(filepath: str) -> dict: # sourcery skip: extract-duplicate-method |
87 | 83 | """Loads the pickled data from the specified file path. If the file doesn't exist, it return an empty dictionary. This method is 'safe' because it handles exceptions and provides a user-friendly error message. |
|
0 commit comments