Skip to content

Commit

Permalink
merge: Fix all pylint complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuestengecko committed Nov 28, 2022
2 parents 397596f + 360b120 commit 5b00162
Show file tree
Hide file tree
Showing 48 changed files with 633 additions and 567 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, merge-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand Down Expand Up @@ -49,7 +49,7 @@ repos:
args:
- --add-ignore=D1
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
additional_dependencies:
Expand All @@ -69,7 +69,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '#'
- "#"
- id: insert-license
name: Insert license headers (XML-style comments)
files: '\.(?:html|md|xml)$'
Expand All @@ -79,7 +79,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '<!--| ~| -->'
- "<!--| ~| -->"
- id: insert-license
name: Insert license headers (C-style comments)
files: '\.(?:css|js|ts)$'
Expand All @@ -89,7 +89,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '/*| *| */'
- "/*| *| */"
- id: insert-license
name: Insert license headers (reST comments)
files: '\.rst$'
Expand All @@ -99,12 +99,12 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '..| |'
- "..| |"
- repo: https://github.com/fsfe/reuse-tool
rev: v1.0.0
hooks:
- id: reuse
- repo: https://github.com/qoomon/git-conventional-commits
rev: v2.1.2
rev: v2.3.0
hooks:
- id: conventional-commits
10 changes: 4 additions & 6 deletions capellambse/aird/diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ def snap_to_parent(self) -> None:

if not isinstance(self.parent, Box):
raise TypeError(
f"Can only snap to parent Boxes, not {type(self.parent).__name__}"
"Can only snap to parent Boxes,"
f" not {type(self.parent).__name__}"
)

if self.port:
Expand Down Expand Up @@ -501,6 +502,7 @@ def __str__(self) -> str:
)

def __repr__(self) -> str:
context = ", ".join(repr(c) for c in sorted(self.context))
return "".join(
[
f"{type(self).__name__}({self.pos!r}, {self.size!r}",
Expand All @@ -511,11 +513,7 @@ def __repr__(self) -> str:
if self.parent is not None
else ""
),
(
f", context={{{', '.join(repr(c) for c in sorted(self.context))}}}"
if self.context
else ""
),
f", context={{{context}}}" if context else "",
f", features={self.features!r}" if self.features else "",
f", styleclass={self.styleclass!r}" if self.styleclass else "",
", hidelabel=True" if self.hidelabel else "",
Expand Down
7 changes: 2 additions & 5 deletions capellambse/aird/parser/_box_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,8 @@ def requirements_box_factory(seb: C.SemanticElementBuilder) -> aird.Box:
box = generic_factory(seb, minsize=aird.Vector2D(0, 0))
box.features = [f"- {i}" for i in text if i is not None]
if not (box.label or box.features):
raise ValueError(
"Requirements text is empty for {!r}".format(
seb.data_element.attrib["element"]
)
)
sdata_element = seb.data_element.attrib["element"]
raise ValueError(f"Requirements text is empty for {sdata_element!r}")
return box


Expand Down
4 changes: 2 additions & 2 deletions capellambse/aird/parser/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def stacking_mode(self, new_mode: str) -> None:
) from None

@property # type: ignore[override]
def features(self) -> cabc.Sequence[str] | None: # type: ignore[override]
def features(self) -> cabc.Sequence[str] | None:
"""Return the list of Box' features."""
return self.__features

Expand Down Expand Up @@ -348,7 +348,7 @@ def __init__(
self.center = center

@property # type: ignore[override]
def pos(self) -> aird.Vector2D: # type: ignore[override]
def pos(self) -> aird.Vector2D:
"""Return the top left corner position of this Box."""
return self.center - self.size / 2

Expand Down
6 changes: 3 additions & 3 deletions capellambse/aird/parser/_edge_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ def generic_factory(seb: C.SemanticElementBuilder) -> aird.Edge:
ostyle = next(seb.diag_element.iterchildren("ownedStyle"))
except StopIteration:
raise ValueError(
"Cannot find style definition for edge {}".format(
seb.data_element.attrib["element"]
)
f"Cannot find style definition for edge"
f" {seb.data_element.attrib['element']}"
) from None
routingstyle = ostyle.attrib.get("routingStyle")

Expand All @@ -59,6 +58,7 @@ def generic_factory(seb: C.SemanticElementBuilder) -> aird.Edge:

_filters.setfilters(seb, edge)
# <https://github.com/python/mypy/issues/8136#issuecomment-565387901>
# pylint: disable-next=line-too-long
edge.styleoverrides = _styling.apply_style_overrides( # type: ignore[assignment]
seb.target_diagram.styleclass, f"Edge.{seb.styleclass}", ostyle
)
Expand Down
7 changes: 5 additions & 2 deletions capellambse/aird/parser/_filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#: Maps names of global filters to functions that implement them
GLOBAL_FILTERS: dict[str, GlobalFilter] = {}

PLUGIN_PATH = "/plugin/org.polarsys.capella.core.sirius.analysis/description/context.odesign#/"
PLUGIN_PATH = (
"/plugin/org.polarsys.capella.core.sirius.analysis"
"/description/context.odesign#/"
)

_TDiagramElement = t.TypeVar("_TDiagramElement", bound=aird.DiagramElement)

Expand Down Expand Up @@ -240,7 +243,7 @@ def _set_composite_filter(
return
if not hasattr(dgobject, "_compfilters"):
dgobject._compfilters = [] # type: ignore[union-attr]
dgobject._compfilters.append((flttype, phase2)) # type: ignore[union-attr]
dgobject._compfilters.append((flttype, phase2))


def _extract_filter_type(flt_elm: etree._Element) -> str:
Expand Down
5 changes: 4 additions & 1 deletion capellambse/aird/parser/_filters/global.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

from . import FilterArguments, composite, global_filter

XT_CEX_FEX_ALLOCATION = "org.polarsys.capella.core.data.fa:ComponentExchangeFunctionalExchangeAllocation"
XT_CEX_FEX_ALLOCATION = (
"org.polarsys.capella.core.data.fa"
":ComponentExchangeFunctionalExchangeAllocation"
)
EXCHANGES_WITH_ROLES = frozenset(
{"Aggregation", "Association", "Composition", "Generalization"}
)
Expand Down
2 changes: 1 addition & 1 deletion capellambse/aird/vector2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Vector2D(t.NamedTuple):
def __add__(self, other: Vec2ish) -> Vector2D: # type: ignore[override]
return self.__map2(operator.add, other)

def __radd__(self, other: Vec2ish) -> Vector2D: # type: ignore[misc]
def __radd__(self, other: Vec2ish) -> Vector2D:
return self.__map2(operator.add, other, True)

def __sub__(self, other: Vec2ish) -> Vector2D:
Expand Down
5 changes: 4 additions & 1 deletion capellambse/extensions/pvmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class PropertyValueProxy:
# pylint: disable=line-too-long
"""Provides access to an element's property values.
Example for accessing property values on any object that has pvmt::
Expand All @@ -27,6 +28,7 @@ class PropertyValueProxy:
Access is only given if the PVMT Extension is successfully
loaded on loading the model with the :class:`MelodyModel`.
"""
# pylint: enable=line-too-long

_model: capellambse.MelodyModel
_element: etree._Element
Expand Down Expand Up @@ -56,7 +58,8 @@ def __getitem__(self, key):
path = key.split(".")
if len(path) < 1 or len(path) > 3:
raise ValueError(
"Provide a name as `domain`, `domain.group` or `domain.group.prop`"
"Provide a name as `domain`, `domain.group` or"
" `domain.group.prop`"
)

domain = _PVMTDomain(self._model, self._element, path[0])
Expand Down
11 changes: 8 additions & 3 deletions capellambse/extensions/reqif/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ def __init__(self) -> None:
},
)

def _match_xtype(self, type_: str) -> tuple[type, str]: # type: ignore[override]
def _match_xtype( # type: ignore[override]
self, type_: str
) -> tuple[type, str]:
type_ = type_.lower()
try:
return _attr_type_hints[type_]
Expand All @@ -342,7 +344,7 @@ def __init__(
source: c.ModelObject,
) -> None:
del elemclass
super().__init__(model, elements, c.GenericElement) # type: ignore[arg-type]
super().__init__(model, elements, AbstractRequirementsRelation)
self._source = source

@t.overload
Expand Down Expand Up @@ -473,7 +475,10 @@ class AttributeDefinitionEnumeration(ReqIFElement):
multi_valued = xmltools.BooleanAttributeProperty(
"_element",
"multiValued",
__doc__="Boolean flag for setting multiple enumeration values on the attribute",
__doc__=(
"Boolean flag for setting multiple enumeration values on"
" the attribute"
),
)


Expand Down
2 changes: 1 addition & 1 deletion capellambse/extensions/reqif/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def export_module(
if not isinstance(target, (str, os.PathLike)):
ctx: t.ContextManager[t.IO[bytes]] = contextlib.nullcontext(target)
else:
ctx = open(target, "wb") # pylint: disable=consider-using-with
ctx = open(target, "wb")

with contextlib.ExitStack() as stack:
container = stack.enter_context(ctx)
Expand Down
11 changes: 4 additions & 7 deletions capellambse/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,15 +648,12 @@ def get_transformation(
size
Size vector
"""
tranformation = dict(
ChoicePseudoState="translate({tx},{ty}) scale({s}) rotate(45,{rx},{ry})",
)
if class_ not in tranformation:
if class_ != "ChoicePseudoState":
return {}

s = 0.725
tx, ty = (1 - s) * pos[0] + 6, (1 - s) * pos[1] + 5
rx, ry = pos[0] + size[0] / 2, pos[1] + size[1] / 2
return dict(
transform=tranformation[class_].format(tx=tx, ty=ty, s=s, rx=rx, ry=ry)
)
return {
"transform": f"translate({tx},{ty}) scale({s}) rotate(45,{rx},{ry})"
}
9 changes: 7 additions & 2 deletions capellambse/loader/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def __load_referenced_files(
self.__load_referenced_files(ref_name)

def save(self, **kw: t.Any) -> None:
# pylint: disable=line-too-long
"""Save all model files back to their original locations.
Parameters
Expand All @@ -443,6 +444,7 @@ def save(self, **kw: t.Any) -> None:
always leave the ``update_cache`` parameter at its default value
of ``True`` if you intend to save changes.
"""
# pylint: enable=line-too-long
self.check_duplicate_uuids()

overwrite_corrupt = kw.pop("i_have_a_recent_backup", False)
Expand Down Expand Up @@ -665,7 +667,8 @@ def follow_href(
roots = [(self._find_fragment(r)[0], r) for r in roots]
else:
raise TypeError(
f"`roots` must be an XML element or a list thereof, not {type(roots).__name__}"
"`roots` must be an XML element or a list thereof,"
f" not {type(roots).__name__}"
)

ret = []
Expand Down Expand Up @@ -1098,7 +1101,9 @@ def get_model_info(self) -> ModelInfo:

try:
comment = semantic_tree.tree.xpath("/comment()")
info.capella_version = CAP_VERSION.match(comment[0].text).group(1) # type: ignore[union-attr]
vers_match = CAP_VERSION.match(comment[0].text)
assert vers_match
info.capella_version = vers_match.group(1)
except (AttributeError, IndexError):
LOGGER.warning(
"Cannot find Capella version: No version comment found"
Expand Down
2 changes: 1 addition & 1 deletion capellambse/loader/exs.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _escape_char(
char = match.group(0)
assert len(char) == 1
if ord_low <= ord(char) <= ord_high:
return "&{};".format(html.entities.codepoint2name[ord(char)])
return f"&{html.entities.codepoint2name[ord(char)]};"
return f"&#x{ord(char):X};"


Expand Down
2 changes: 1 addition & 1 deletion capellambse/loader/filehandler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
subdir: str | pathlib.PurePosixPath = "/",
**kw: t.Any,
) -> None:
super().__init__(**kw) # type: ignore[call-arg]
super().__init__(**kw)
self.path = path
self.subdir = subdir

Expand Down
3 changes: 2 additions & 1 deletion capellambse/loader/filehandler/gitfilehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def __init__(

if _git_object_name.search(targetref):
raise ValueError(
f"Target ref looks like a git object, use a different remote_branch: {targetref}"
"Target ref looks like a git object, use a different"
f" remote_branch: {targetref}"
)
if not targetref.startswith("refs/heads/"):
targetref = "refs/heads/" + targetref
Expand Down
3 changes: 2 additions & 1 deletion capellambse/loader/filehandler/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ def __init__(
"""
if not isinstance(path, str):
raise TypeError(
f"HTTPFileHandler requires a str path, not {type(path).__name__}"
"HTTPFileHandler requires a str path, not"
f" {type(path).__name__}"
)
if bool(username) != bool(password):
raise ValueError(
Expand Down
Loading

0 comments on commit 5b00162

Please sign in to comment.