From 03ba6568a3de3570e7c68f3abce3e9dc9984e3bd Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Thu, 19 Sep 2024 19:21:03 -0700 Subject: [PATCH] lint --- .../src/nwb_linkml/adapters/namespaces.py | 13 +++++--- .../src/nwb_schema_language/util.py | 30 ++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py index 326da7c..70e6f89 100644 --- a/nwb_linkml/src/nwb_linkml/adapters/namespaces.py +++ b/nwb_linkml/src/nwb_linkml/adapters/namespaces.py @@ -224,7 +224,7 @@ class NamespacesAdapter(Adapter): return parents - def _overwrite_class(self, new_cls: Dataset | Group, old_cls: Dataset | Group): + def _overwrite_class(self, new_cls: Dataset | Group, old_cls: Dataset | Group) -> None: """ Overwrite the version of a dataset or group that is stored in our schemas """ @@ -264,9 +264,14 @@ class NamespacesAdapter(Adapter): matches = [] for schema in self.all_schemas(): in_schema = False - if isinstance(cls, str) and cls in [ - c.neurodata_type_def for c in schema.created_classes - ] or isinstance(cls, Dataset) and cls in schema.datasets or isinstance(cls, Group) and cls in schema.groups: + if ( + isinstance(cls, str) + and cls in [c.neurodata_type_def for c in schema.created_classes] + or isinstance(cls, Dataset) + and cls in schema.datasets + or isinstance(cls, Group) + and cls in schema.groups + ): in_schema = True if in_schema: diff --git a/nwb_schema_language/src/nwb_schema_language/util.py b/nwb_schema_language/src/nwb_schema_language/util.py index 61bc5ed..ef910a8 100644 --- a/nwb_schema_language/src/nwb_schema_language/util.py +++ b/nwb_schema_language/src/nwb_schema_language/util.py @@ -1,27 +1,37 @@ -from pprint import pformat as _pformat -import textwrap +""" +The fabled junk drawer +""" + import re +import textwrap +from pprint import pformat as _pformat def pformat(fields: dict, cls_name: str, indent: str = " ") -> str: """ - pretty format the fields of the items of a ``YAMLRoot`` object without the wonky indentation of pformat. - see ``YAMLRoot.__repr__``. + pretty format the fields of the items of a ``YAMLRoot`` object without the + wonky indentation of pformat. - formatting is similar to black - items at similar levels of nesting have similar levels of indentation, - rather than getting placed at essentially random levels of indentation depending on what came before them. + formatting is similar to black - + items at similar levels of nesting have similar levels of indentation, + rather than getting placed at essentially random levels of indentation + depending on what came before them. """ res = [] total_len = 0 for key, val in fields.items(): if val == [] or val == {} or val is None: continue - # pformat handles everything else that isn't a YAMLRoot object, but it sure does look ugly - # use it to split lines and as the thing of last resort, but otherwise indent = 0, we'll do that + # pformat handles everything else that isn't a YAMLRoot object, + # but it sure does look ugly + # use it to split lines and as the thing of last resort, + # but otherwise indent = 0, we'll do that val_str = _pformat(val, indent=0, compact=True, sort_dicts=False) - # now we indent everything except the first line by indenting and then using regex to remove just the first indent + # now we indent everything except the first line by indenting + # and then using regex to remove just the first indent val_str = re.sub(rf"\A{re.escape(indent)}", "", textwrap.indent(val_str, indent)) - # now recombine with the key in a format that can be re-eval'd into an object if indent is just whitespace + # now recombine with the key in a format that can be re-eval'd + # into an object if indent is just whitespace val_str = f"'{key}': " + val_str # count the total length of this string so we know if we need to linebreak or not later