diff --git a/nomenclature/codelist.py b/nomenclature/codelist.py index d101c236..e371f241 100644 --- a/nomenclature/codelist.py +++ b/nomenclature/codelist.py @@ -272,8 +272,8 @@ def to_yaml(self, path=None): """ class Dumper(yaml.Dumper): - def increase_indent(self, flow=False, *args, **kwargs): - return super().increase_indent(flow=flow, indentless=False) + def increase_indent(self, flow: bool = False, indentless: bool = False): + return super().increase_indent(flow=flow, indentless=indentless) # translate to list of nested dicts, replace None by empty field, write to file stream = ( @@ -286,11 +286,10 @@ def increase_indent(self, flow=False, *args, **kwargs): .replace(": nan\n", ":\n") ) - if path is not None: - with open(path, "w") as file: - file.write(stream) - else: + if path is None: return stream + with open(path, "w") as file: + file.write(stream) def to_pandas(self, sort_by_code: bool = False) -> pd.DataFrame: """Export the CodeList to a :class:`pandas.DataFrame` @@ -589,7 +588,7 @@ def hierarchy(self) -> List[str]: List[str] """ - return sorted(list(set(v.hierarchy for v in self.mapping.values()))) + return sorted(list({v.hierarchy for v in self.mapping.values()})) def filter(self, hierarchy: str) -> "RegionCodeList": """Return a filtered RegionCodeList object diff --git a/nomenclature/core.py b/nomenclature/core.py index e228f924..c3d8a1e9 100644 --- a/nomenclature/core.py +++ b/nomenclature/core.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) -@validate_arguments(config=dict(arbitrary_types_allowed=True)) +@validate_arguments(config={"arbitrary_types_allowed": True}) def process( df: pyam.IamDataFrame, dsd: DataStructureDefinition,