Skip to content

Commit 396b8c0

Browse files
committed
Remove assert statements for type checks
Removed those `assert` statements which verified only the type. At the beginning of the project these assertions had been used to develop a reliable implementation in the sense of ISO 26262, but the (ongoing) tool qualification efforts allow to follow Python's duck typing philosophy again.
1 parent b1620d4 commit 396b8c0

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

lobster/htmldoc/htmldoc.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import html
2121
from abc import abstractmethod, ABC
22-
from typing import List
22+
from typing import List, Optional
2323

2424
from lobster.htmldoc import assets
2525

@@ -50,13 +50,11 @@ def generate(self, doc) -> List[str]:
5050

5151
class Menu_Link(Menu_Item):
5252
def __init__(self, name, target):
53-
assert isinstance(target, str)
5453
super().__init__(name)
5554

5655
self.target = target
5756

5857
def generate(self, doc) -> List[str]:
59-
assert isinstance(doc, Document)
6058
rv = (
6159
f'<a href="{self.target}" '
6260
f'id="menu-item-{html.escape(self.name).replace(" ", "-").lower()}">'
@@ -77,7 +75,6 @@ def add_link(self, name, target):
7775
self.items.append(Menu_Link(name, target))
7876

7977
def generate(self, doc) -> List[str]:
80-
assert isinstance(doc, Document)
8178

8279
doc.style["#navbar .dropdown"] = {
8380
"float" : "left",
@@ -169,8 +166,6 @@ def add_dropdown(self, name, alignment="left"):
169166
return menu
170167

171168
def generate(self, doc):
172-
assert isinstance(doc, Document)
173-
174169
doc.style["#navbar"] = {
175170
"overflow" : "hidden",
176171
"background-color" : doc.primary_color,
@@ -218,8 +213,6 @@ def generate(self, doc):
218213

219214
class Document:
220215
def __init__(self, title, subtitle):
221-
assert isinstance(title, str)
222-
assert isinstance(subtitle, str)
223216
self.title = title
224217
self.subtitle = subtitle
225218

@@ -259,16 +252,18 @@ def __init__(self, title, subtitle):
259252
self.css = []
260253

261254
def add_line(self, line):
262-
assert isinstance(line, str)
263255
if len(self.body) == 0:
264256
self.body.append('<div class="content">')
265257
self.body.append(line)
266258

267-
def add_heading(self, level, text, anchor=None, html_identifier=False):
268-
assert isinstance(level, int)
269-
assert isinstance(text, str)
259+
def add_heading(
260+
self,
261+
level: int,
262+
text: str,
263+
anchor: Optional[str] = None,
264+
html_identifier: bool = False,
265+
):
270266
assert 2 <= level <= 7
271-
assert anchor is None or isinstance(anchor, str)
272267

273268
if level == 2 and self.body:
274269
self.body.append("</div>")

0 commit comments

Comments
 (0)