Skip to content

Commit 9707c6f

Browse files
mid ruff linting
1 parent f89d26a commit 9707c6f

File tree

12 files changed

+68
-24
lines changed

12 files changed

+68
-24
lines changed

linkml_runtime/linkml_model/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from .meta import (
44
AltDescription,
55
AltDescriptionSource,
6+
AnonymousClassExpression,
7+
AnonymousEnumExpression,
8+
AnonymousExpression,
9+
AnonymousSlotExpression,
10+
AnonymousTypeExpression,
611
ClassDefinition,
712
ClassDefinitionName,
813
Definition,
@@ -90,4 +95,9 @@
9095
"AltDescription",
9196
"PermissibleValue",
9297
"PvFormulaOptions",
98+
"AnonymousClassExpression",
99+
"AnonymousEnumExpression",
100+
"AnonymousExpression",
101+
"AnonymousSlotExpression",
102+
"AnonymousTypeExpression",
93103
]

linkml_runtime/utils/permissiblevalueimpl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from typing import Any, ClassVar, Optional, Union
33

44
from rdflib import URIRef
5-
from utils.enumerations import EnumDefinitionImpl
65

76
from linkml_runtime.utils.curienamespace import CurieNamespace
7+
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
88
from linkml_runtime.utils.metamodelcore import URI, URIorCURIE, empty_list
99
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str
1010

linkml_runtime/utils/ruleutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ def subclass_to_rules(
136136

137137

138138
def rule_subsumed_by_class(view: SchemaView, rule, cls: ClassDefinition):
139-
induced_slots = view.class_induced_slots(cls.name)
139+
# induced_slots = view.class_induced_slots(cls.name)
140140
return False
141141

142142

143143
def remove_redundant_rules(view: SchemaView, class_name: ClassDefinitionName):
144-
induced_slots = view.class_induced_slots(class_name)
144+
# induced_slots = view.class_induced_slots(class_name)
145145
cls = view.get_class(class_name)
146146
redundant_rules = []
147147
for rule in cls.rules:

linkml_runtime/utils/schemaops.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def roll_up(sv: SchemaView, classes: CLASS_NAME_OR_LIST = None, mixins=True, is_
2222
dels = set()
2323
for cn in classes:
2424
c = sv.get_class(cn)
25-
slots = []
2625
for d in sv.class_descendants(cn, reflexive=False, mixins=mixins, is_a=is_a):
2726
for sn in sv.class_slots(d):
2827
s = sv.induced_slot(sn, class_name=d)
@@ -54,7 +53,6 @@ def roll_down(sv: SchemaView, classes: list[CLASS_NAME] = None, mixins=True, is_
5453
dels = set()
5554
for cn in classes:
5655
c = sv.get_class(cn)
57-
slots = []
5856
for d in sv.class_ancestors(cn, reflexive=False, mixins=mixins, is_a=is_a):
5957
for sn in sv.class_slots(d):
6058
s = sv.induced_slot(sn, class_name=d)
@@ -74,6 +72,5 @@ def roll_down(sv: SchemaView, classes: list[CLASS_NAME] = None, mixins=True, is_
7472
if is_a and c.is_a is not None:
7573
del c.is_a
7674
for d in dels:
77-
d_cls = sv.get_class(d)
7875
sv.delete_class(d)
7976
sv.set_modified()

linkml_runtime/utils/schemaview.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,38 @@
66
from collections import defaultdict, deque
77
from collections.abc import Mapping
88
from copy import copy, deepcopy
9+
from dataclasses import dataclass
910
from enum import Enum
1011
from functools import lru_cache
1112
from pathlib import Path
12-
from typing import Optional, TypeVar
13+
from typing import Any, Optional, TypeVar, Union
1314

1415
from deprecated.classic import deprecated
1516

1617
from linkml_runtime.exceptions import OrderingError
17-
from linkml_runtime.linkml_model.meta import *
18+
from linkml_runtime.linkml_model import (
19+
AnonymousSlotExpression,
20+
ClassDefinition,
21+
ClassDefinitionName,
22+
Definition,
23+
DefinitionName,
24+
Element,
25+
ElementName,
26+
EnumDefinition,
27+
EnumDefinitionName,
28+
PermissibleValueText,
29+
SchemaDefinition,
30+
SchemaDefinitionName,
31+
SlotDefinition,
32+
SlotDefinitionName,
33+
SubsetDefinition,
34+
SubsetDefinitionName,
35+
TypeDefinition,
36+
TypeDefinitionName,
37+
)
1838
from linkml_runtime.utils.context_utils import map_import, parse_import_map
1939
from linkml_runtime.utils.formatutils import camelcase, is_empty, underscore
40+
from linkml_runtime.utils.metamodelcore import URIorCURIE
2041
from linkml_runtime.utils.namespaces import Namespaces
2142
from linkml_runtime.utils.pattern import PatternResolver
2243

@@ -1117,7 +1138,7 @@ def get_uri(self, element: Union[ElementName, Element], imports=True, expand=Fal
11171138
if uri is None or native:
11181139
if e.from_schema is not None:
11191140
schema = next(sc for sc in self.schema_map.values() if sc.id == e.from_schema)
1120-
if schema == None:
1141+
if schema is None:
11211142
raise ValueError(f"Cannot find {e.from_schema} in schema_map")
11221143
else:
11231144
schema = self.schema_map[self.in_schema(e.name)]

linkml_runtime/utils/yamlutils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from yaml.constructor import ConstructorError
1313

1414
from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE, merge_contexts
15-
from linkml_runtime.utils.formatutils import is_empty, items
15+
from linkml_runtime.utils.formatutils import is_empty
1616

1717
YAMLObjTypes = Union[JsonObjTypes, "YAMLRoot"]
1818

@@ -229,16 +229,20 @@ def _normalize_inlined_slot(
229229
self.<slot> = []
230230
if not isinstance(self.<slot>, list):
231231
self.extensions = [self.<slot>]
232-
self._normalize_inlined_slot(slot_name="<slot>", slot_type=<type>, key_name="<key>", inlined_as_list=True, keyed=...)
232+
self._normalize_inlined_slot(
233+
slot_name="<slot>", slot_type=<type>, key_name="<key>", inlined_as_list=True, keyed=...
234+
)
233235
or
234236
if self.<slot> is None:
235237
self.<slot> = []
236238
if not isinstance(self.<slot>, (list, dict)):
237239
self.local_names = [self.<slot>]
238-
self._normalize_inlined_slot(slot_name="<slot>", slot_type=<type>, key_name="<key>", inlined_as_list=None, keyed=...)
240+
self._normalize_inlined_slot(
241+
slot_name="<slot>", slot_type=<type>, key_name="<key>", inlined_as_list=None, keyed=...
242+
)
239243
240-
The above pattern broke when the new jsonasobj was introduced, which is why we have the normalization above. The code
241-
below reverse engineers the above and invokes the new form
244+
The above pattern broke when the new jsonasobj was introduced, which is why we have the normalization above.
245+
The code below reverse engineers the above and invokes the new form
242246
243247
"""
244248
if inlined_as_list:
@@ -305,7 +309,8 @@ def _pformat(fields: dict, cls_name: str, indent: str = " ") -> str:
305309
# pformat handles everything else that isn't a YAMLRoot object, but it sure does look ugly
306310
# use it to split lines and as the thing of last resort, but otherwise indent = 0, we'll do that
307311
val_str = pformat(val, indent=0, compact=True, sort_dicts=False)
308-
# now we indent everything except the first line by indenting and then using regex to remove just the first indent
312+
# now we indent everything except the first line by indenting
313+
# and then using regex to remove just the first indent
309314
val_str = re.sub(rf"\A{re.escape(indent)}", "", textwrap.indent(val_str, indent))
310315
# now recombine with the key in a format that can be re-eval'd into an object if indent is just whitespace
311316
val_str = f"'{key}': " + val_str

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ select = [
100100
"UP", # pyupgrade
101101
]
102102
force-exclude = true
103-
extend-ignore = ["E203"]
103+
extend-ignore = [
104+
"E203",
105+
"UP007", # until we drop 3.9
106+
]
104107

105108
# -- Exclude files --
106109
extend-exclude = [
@@ -110,6 +113,9 @@ extend-exclude = [
110113
"notebooks/"
111114
]
112115

116+
[tool.ruff.per-file-ignores]
117+
"tests/**/**.py" = ["F841", "E501", "F842", "E741"] # I ain't fixing all that
118+
113119
[tool.codespell]
114120
skip = '.git,*.pdf,*.svg,./tests,pyproject.toml,*.dill,poetry.lock'
115121
# Ignore table where words could be split across rows

tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import configparser
2-
import logging
32

43
# Global testing control variables
54
import os
65

76
from tests.support.test_environment import MismatchAction
87

8+
__all__ = [
9+
"MismatchAction",
10+
]
11+
912
# ---------------------------------------------------------------
1013
# DO NOT change this file.
1114
# To change the default test harness settings:

tests/support/test_environment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def no_click_exit(_self, code=0):
2222

2323

2424
# This import has to occur here
25-
import click
25+
import click # noqa: E402
2626

2727
click.core.Context.exit = no_click_exit
2828

@@ -209,8 +209,9 @@ def generate_single_file(
209209
:return: the generator output
210210
"""
211211
# If no filter, default to identity function
212-
if not filtr:
213-
filtr = lambda s: s
212+
if filtr is None:
213+
def filtr(s):
214+
return s
214215
filename = filename if isinstance(filename, list) else [filename]
215216
actual_file = self.root_temp_file_path(*filename) if use_testing_root else self.actual_path(*filename)
216217
expected_file = self.root_expected_path(*filename) if use_testing_root else self.expected_path(*filename)

tests/test_issues/test_linkml_runtime_issue_68.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_issue_68(self):
107107

108108
s3_induced_c2 = view.induced_slot("slot3", "class2")
109109
assert not s3_induced_c2.required
110-
assert s3_induced_c2.description == None
110+
assert s3_induced_c2.description is None
111111
assert s3_induced_c2.range == "class0"
112112

113113
# mixins take priority over is-a

0 commit comments

Comments
 (0)