SMB3-Foundry
SMB3-Foundry copied to clipboard
Add NamedTuples and DataClasses for Better Documentation
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. When passing tuples around to represent, palettes, positions, and size, it can often times become confusing and hard to understand. This effect is amplified by poor documentation and comments.
Describe the solution you'd like A clear and concise description of what you want to happen.
The use of a NamedTuple or DataClass to represent these common structs in code would greatly add readability and documentation to the repo. Using a NamedTuple over a Tuple provides little difference in performance while providing higher maintainability. Furthermore, both a NamedTuple and DataClass can be implemented to be backwards compatible with older code, allowing it to be added immediately without requiring any change in code.
The scope of this issue is the creation of NamedTuples and DataClasses for the items mentioned above with the expectation that future issues will be created to add these self-documenting tools into the repo. Specific areas that come time mind include objects code for levels and most of the GUI.
Example:
def set_position(position: Tuple[int, int]) -> None:
self.x, self.y = position[0], position[1]
Transforms into:
def set_position(position: Union[Position, Tuple[int, int]]) -> None:
try:
self.x, self.y = position.x, position.y
except AttributeError:
self.x, self.y = position[0], position[1]
Or alternatively the first solution can be utilized with full backwards compatibility.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. They're likely other solutions to this problem that I have failed to address, but I believe most solutions follow a similar motif.
Additional context Add any other context or screenshots about the feature request here.
A DataClass should be favored over a NamedTuple when the data should be mutable, otherwise a NamedTuple should be utilized. You can also apply additional methods to both types. For example, you can provide better reprs and str methods to the classes if desired.