diff --git a/demo/horizontal/emmo2meta.py b/demo/horizontal/emmo2meta.py index 9ca36036d..1c4538938 100644 --- a/demo/horizontal/emmo2meta.py +++ b/demo/horizontal/emmo2meta.py @@ -174,7 +174,7 @@ def get_properties(self, cls): # pylint: disable=too-many-locals props = [] dimindices = {} propnames = set() - types = dict(Integer="int", Real="double", String="string") + types = {"Integer": "int", "Real": "double", "String": "string"} def get_dim(restriction, name, descr=None): """Returns dimension index corresponding to dimension name `name` diff --git a/ontopy/graph.py b/ontopy/graph.py index ec142243a..ba69d4dff 100644 --- a/ontopy/graph.py +++ b/ontopy/graph.py @@ -264,7 +264,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals self.edges = set() else: if ontology != graph.ontology: - ValueError( + raise ValueError( "the same ontology must be used when extending a graph" ) self.dot = graph.dot.copy() diff --git a/ontopy/ontodoc.py b/ontopy/ontodoc.py index 3092d13bc..e14637e1c 100644 --- a/ontopy/ontodoc.py +++ b/ontopy/ontodoc.py @@ -49,20 +49,20 @@ class OntoDoc: annotation values. """ - _markdown_style = dict( - sep="\n", - figwidth="{{ width={width:.0f}px }}", - figure="![{caption}]({path}){figwidth}\n", - header="\n{:#<{level}} {label}", - link="[{name}]({lowerurl})", - point=" - {point}\n", - points="\n\n{points}\n", - annotation="**{key}:** {value}\n", - substitutions=[], - ) + _markdown_style = { + "sep": "\n", + "figwidth": "{{ width={width:.0f}px }}", + "figure": "![{caption}]({path}){figwidth}\n", + "header": "\n{:#<{level}} {label}", + "link": "[{name}]({lowerurl})", + "point": " - {point}\n", + "points": "\n\n{points}\n", + "annotation": "**{key}:** {value}\n", + "substitutions": [], + } # Extra style settings for markdown+tex (e.g. pdf generation with pandoc) - _markdown_tex_extra_style = dict( - substitutions=[ + _markdown_tex_extra_style = { + "substitutions": [ # logic/math symbols ("\u2200", r"$\\forall$"), ("\u2203", r"$\\exists$"), @@ -132,17 +132,17 @@ class OntoDoc: ("\u014d", r"$\\bar{\\mathrm{o}}$"), ("\u1f45", r"$\\acute{o}$"), # no \omicron ], - ) - _html_style = dict( - sep="
\n",
- figwidth='width="{width:.0f}"',
- figure='',
- header='
\n",
+ "figwidth": 'width="{width:.0f}"',
+ "figure": '',
+ "header": '
", r"
\n\n"),
(r"\u2018([^\u2019]*)\u2019", r"\1
"),
@@ -154,7 +154,7 @@ class OntoDoc:
(r"\u226B", r"&x226B;"),
(r'"Y$', r""), # strange noice added by owlready2
],
- )
+ }
def __init__(self, onto, style="markdown"):
if isinstance(style, str):
@@ -243,15 +243,15 @@ def itemdoc(
substitutions = self.style.get("substitutions", [])
# Logical "sorting" of annotations
- order = dict(
- definition="00",
- axiom="01",
- theorem="02",
- elucidation="03",
- domain="04",
- range="05",
- example="06",
- )
+ order = {
+ "definition": "00",
+ "axiom": "01",
+ "theorem": "02",
+ "elucidation": "03",
+ "domain": "04",
+ "range": "05",
+ "example": "06",
+ }
doc = []
@@ -409,7 +409,6 @@ def itemdoc(
key="Individuals", value=value, ontology=onto
)
)
-
return "\n".join(doc)
def itemsdoc(self, items, header_level=3):
diff --git a/ontopy/ontology.py b/ontopy/ontology.py
index 90eed6c08..d3fd267b1 100644
--- a/ontopy/ontology.py
+++ b/ontopy/ontology.py
@@ -220,8 +220,7 @@ def __contains__(self, other):
self.get_by_label(other)
except NoSuchLabelError:
return False
- else:
- return True
+ return True
def __objclass__(self):
# Play nice with inspect...
@@ -782,7 +781,7 @@ def save(
fmt = revmap.get(format, format)
filename = f"{self.name}.{fmt}"
else:
- TypeError("`filename` and `format` cannot both be None.")
+ raise TypeError("`filename` and `format` cannot both be None.")
filename = os.path.join(dir, filename)
dir = Path(filename).resolve().parent
@@ -1465,7 +1464,9 @@ def closest_common_ancestor(*classes):
return cur
if len(mro) == 0:
mros.remove(mro)
- raise Exception("A closest common ancestor should always exist !")
+ raise EMMOntoPyException(
+ "A closest common ancestor should always exist !"
+ )
def get_ancestors(self, classes, include="all", strict=True):
"""Return ancestors of all classes in `classes`.
diff --git a/ontopy/patch.py b/ontopy/patch.py
index d67525dcb..6a957e2cc 100644
--- a/ontopy/patch.py
+++ b/ontopy/patch.py
@@ -5,6 +5,7 @@
import owlready2
from owlready2 import ThingClass, PropertyClass, Thing, Restriction, Namespace
from owlready2 import Metadata
+from ontopy.utils import EMMOntoPyException
def render_func(entity):
@@ -60,7 +61,9 @@ def get_parents(self, strict=False):
for cls in self.is_a
if isinstance(cls, owlready2.ObjectPropertyClass)
}
- raise Exception("self has no parents - this should not be possible!")
+ raise EMMOntoPyException(
+ "self has no parents - this should not be possible!"
+ )
def _dir(self):