Skip to content

Commit 4d47225

Browse files
committed
docs: remove unnecessary docstring in user_data to use a single comment instead
1 parent 774c013 commit 4d47225

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/mastermind/main/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self):
8383
while self.main_menu():
8484
pass # keep calling self.main_menu() until it return False
8585
print("Thank you for playing!")
86-
userdata.save_data()
86+
userdata._save_data()
8787

8888

8989
def main():

src/mastermind/storage/user_data.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Callable
2-
from typing import Any
32
from functools import partial
3+
from typing import Any
44

55
from mastermind.storage.pickle_io import (
66
delete_pickled_data,
@@ -62,26 +62,22 @@ def _modify_item(self, key: str, value: Any) -> None:
6262
self._data[key] = value
6363
self.save_data()
6464

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
6569
def __getattr__(self, key: str) -> Any:
66-
"""Retrieves the value associated with the given key."""
6770
return self._retrieve_item(key)
6871

6972
def __getitem__(self, key: str) -> Any:
70-
"""Retrieves the value associated with the given key."""
7173
return self._retrieve_item(key)
7274

7375
def __setattr__(self, key: str, value: Any) -> None:
74-
"""Modifies the value associated with the given key, and saves the changes."""
7576
self._modify_item(key, value)
7677

7778
def __setitem__(self, key: str, value: Any) -> None:
78-
"""Modifies the value associated with the given key, and saves the changes."""
7979
self._modify_item(key, value)
8080

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-
8581

8682
def _load_data_safely(filepath: str) -> dict: # sourcery skip: extract-duplicate-method
8783
"""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

Comments
 (0)