Here is the example of my implementation:
class FileHandler:
__slots__ = ("_target_path",)
def __init__(self, target_path: Path) -> None:
self._target_path = target_path
class Downloader(FileHandler):
__slots__ = ("_url", "_downloaded_bytes")
def __init__(self, target_path: Path, url: str) -> None:
super().__init__(target_path)
self._url = url
self._downloaded_bytes = 0
... There is more stuff but that is not necessary here. In short, all the methods work in the downlaoder including download() and they all use the target_path as well as the _url and the _downlaoded_bytes, now here is something funny when I print the following:
Test and results in the next field...
foo.py
from pathlib import Path
from solutions.file.downloader import Downloader
url = "https://www.unicode.org/Public/UCD/latest/ReadMe.txt"
path = Path(__file__).parent / "unicode.txt"
def foo():
downloader = Downloader(path, url)
return downloader.__slots__
if __name__ == "__main__":
foo_val = foo()
print(foo_val) if not foo_val is None else None
--- CONSOLE OUTPUT BELOW LINE ---
('_url', '_downloaded_bytes')
--- END OF OUTPUT ---
So, it somehow appears to work. However, is my implementation correct? Also, does it still work like legitimate slots or does it decide not to use slots and uses more memory instead?
I am still a beginner so excuse my ignorance. All answers are appreciated. Thank you!