diff --git a/PyTeX/format/formatting_config.py b/PyTeX/format/formatting_config.py index b5840e2..2f4e619 100644 --- a/PyTeX/format/formatting_config.py +++ b/PyTeX/format/formatting_config.py @@ -1,22 +1,29 @@ -from typing import List, Optional, Union +from typing import List, Optional, Union, Any, Tuple from .enums import NamingScheme, License from .generic_text import GenericText -def generate_properties(attr_names): +def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]): + attributes = [ + x if isinstance(x, Tuple) else (x, None) for x in attributes + ] + def decorator(cls): - for attr_name in attr_names: - def get_attr(self, attr_name=attr_name): - return getattr(self, "_" + attr_name) + for [attribute, default_value] in attributes: + def get_attr(self, attribute=attribute, default_value=default_value): + if getattr(self, "_" + attribute) is not None: + return getattr(self, "_" + attribute) + else: + return default_value prop = property(get_attr) - setattr(cls, attr_name, prop) + setattr(cls, attribute, prop) return cls return decorator -@generate_properties(['naming_scheme']) +@generate_properties([('naming_scheme', False), 'license']) class FormattingConfig: def __init__(self): self._naming_scheme: Optional[Union[NamingScheme, str]] = None