Skip to content

Commit 1729256

Browse files
Fix a typing error (coveooss#162)
In md_template.properties_table, we call: escape_for_table(sub_property.property_name) `sub_property` is a `SchemaNode`, making `property_name` an `Optional[str]`. `escape_for_table` expected `str` as input. Adjust it to accept `Optional[str]`. Co-authored-by: Denis Blanchette <[email protected]>
1 parent 286c930 commit 1729256

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

json_schema_for_humans/md_template.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Union
1+
from typing import Dict, List, Union, Optional
22
from urllib.parse import quote_plus, quote
33

44
import jinja2
@@ -32,8 +32,10 @@ def get_numeric_maximum_restriction(schema_node: SchemaNode, default: str = "N/A
3232
return maximum_fragment
3333

3434

35-
def escape_for_table(example_text: str) -> str:
35+
def escape_for_table(example_text: Optional[str]) -> str:
3636
"""Filter. escape characters('|', '`') in string to be inserted into markdown table"""
37+
if example_text is None:
38+
return ""
3739
return example_text.translate(str.maketrans({"|": "\\|", "`": "\\`"}))
3840

3941

@@ -316,7 +318,7 @@ def properties_table(self, schema: SchemaNode) -> List[List]:
316318
"""
317319
properties = []
318320
for sub_property in schema.iterate_properties:
319-
line = []
321+
line: List[str] = []
320322
# property name
321323
property_name = "+ " if sub_property.is_required_property else "- "
322324
property_name += self.format_link(escape_for_table(sub_property.property_name), sub_property.html_id)

0 commit comments

Comments
 (0)