Last active
July 22, 2022 08:21
-
-
Save Drvanon/83be273a95be0d0beda33f99546a27b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassBuilder: | |
def __init__(self): | |
self.data = {} | |
def load_source1(self, params_for_source1): | |
self.data.update(api_call_source1(params_for_source1)) | |
def load_source1(self, params_for_source2): | |
self.data.update(api_call_source1(params_for_source2)) | |
def load_from_file(self, file_name): | |
self.data.update(extract_data_from_file(file_name)) | |
def create(): | |
return MyClass(data=data) | |
# Should make this immutable somehow. | |
class MyClass: | |
data: dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class MyClass: | |
name: str | |
data: str | |
def load_from_source1(self, params_for_source1): | |
self.data.update(api_call_source1(params_for_source1)) | |
def load_from_source2(self, params_for_source2): | |
self.data.update(api_call_source1(params_for_source2)) | |
def load_from_file(self, file_name): | |
self.data.update(extract_data_from_file(file_name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment