Skip to content

Commit

Permalink
Rename JsonDataType
Browse files Browse the repository at this point in the history
- Fix mypy errors
- Add TODO about using TypedDict in Python3.8
  • Loading branch information
russellkan committed Apr 8, 2020
1 parent df04a71 commit dfc9b06
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions dicom_standard/extract_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def attribute_table_to_list(table_div: Tag) -> List[List[str]]:
for row in pr.table_rows(table_div)]


# TODO: Convert attributes to a TypedDict when we update to use Python3.8
def attribute_table_to_json(table: List[TableDictType]) -> List[TableDictType]:
attributes = []
for attr in table:
Expand Down
3 changes: 2 additions & 1 deletion dicom_standard/extract_ciod_module_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from dicom_standard import parse_lib as pl
from dicom_standard import parse_relations as pr
from dicom_standard.macro_utils import MetadataTableType
from dicom_standard.table_utils import (
TableListType,
TableDictType,
Expand All @@ -36,7 +37,7 @@ def ciod_table_to_dict(table: TableListType) -> List[TableDictType]:
return table_to_dict(table, COLUMN_TITLES)


def get_table_with_metadata(table_with_tdiv: Tuple[List[TableDictType], Tag]) -> pl.MetadataTableType:
def get_table_with_metadata(table_with_tdiv: Tuple[List[TableDictType], Tag]) -> MetadataTableType:
table, tdiv = table_with_tdiv
clean_name = pl.clean_table_name(pr.table_name(tdiv))
table_description = get_table_description(tdiv)
Expand Down
2 changes: 1 addition & 1 deletion dicom_standard/macro_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from bs4 import BeautifulSoup, Tag

from dicom_standard.hierarchy_utils import get_hierarchy_markers
from dicom_standard.parse_lib import MetadataTableType

AttributeType = Dict[str, str]
MetadataTableType = Dict[str, Any]
MacrosType = Dict[str, MetadataTableType]


Expand Down
9 changes: 4 additions & 5 deletions dicom_standard/parse_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
ID_PATTERN = re.compile(r'\b(' + '|'.join(NONSTANDARD_SECTION_IDS) + r').+\b')
SHORT_DICOM_URL_PREFIX = "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/"

MetadataTableType = Dict[str, Any]
JsonDataType = Union[List[MetadataTableType], MetadataTableType]
GenericTableType = Union[List[Dict[str, Any]], Dict[str, Any]]


def parse_html_file(filepath: str) -> BeautifulSoup:
Expand All @@ -43,11 +42,11 @@ def write_pretty_json(data: Any) -> None:
json.dump(data, sys.stdout, sort_keys=False, indent=4, separators=(',', ':'))


def read_json_data(filepath: str) -> JsonDataType:
def read_json_data(filepath: str) -> GenericTableType:
with open(filepath, 'r') as json_file:
json_string = json_file.read()
json_dict = json.loads(json_string)
return json_dict
json_data = json.loads(json_string)
return json_data


def all_tdivs_in_chapter(standard: BeautifulSoup, chapter_name: str) -> List[Tag]:
Expand Down
6 changes: 3 additions & 3 deletions dicom_standard/preprocess_macros_with_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import sys

from dicom_standard import parse_lib as pl

from preprocess_modules_with_attributes import (
from dicom_standard.macro_utils import MetadataTableType
from dicom_standard.preprocess_modules_with_attributes import (
key_tables_by_id,
expand_all_macros,
preprocess_attribute_fields,
Expand All @@ -12,7 +12,7 @@


if __name__ == '__main__':
module_macro_attr_tables = cast(List[pl.MetadataTableType], pl.read_json_data(sys.argv[1]))
module_macro_attr_tables = cast(List[MetadataTableType], pl.read_json_data(sys.argv[1]))
id_to_table = key_tables_by_id(module_macro_attr_tables)
macro_attr_tables = [table for table in module_macro_attr_tables if table['isMacro']]
expanded_tables = expand_all_macros(macro_attr_tables, id_to_table)
Expand Down
6 changes: 3 additions & 3 deletions dicom_standard/preprocess_modules_with_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import sys

from dicom_standard import parse_lib as pl
from dicom_standard.macro_utils import expand_macro_rows, get_id_from_link
from dicom_standard.macro_utils import MetadataTableType, expand_macro_rows, get_id_from_link
from dicom_standard.hierarchy_utils import record_hierarchy_for_module


def key_tables_by_id(table_list: List[pl.MetadataTableType]) -> Dict[str, pl.MetadataTableType]:
def key_tables_by_id(table_list: List[MetadataTableType]) -> Dict[str, MetadataTableType]:
dict_of_tables = {}
for table in table_list:
dict_of_tables[get_id_from_link(table['linkToStandard'])] = table
Expand Down Expand Up @@ -62,7 +62,7 @@ def expand_hierarchy(tables):


if __name__ == '__main__':
module_macro_attr_tables = cast(List[pl.MetadataTableType], pl.read_json_data(sys.argv[1]))
module_macro_attr_tables = cast(List[MetadataTableType], pl.read_json_data(sys.argv[1]))
id_to_table = key_tables_by_id(module_macro_attr_tables)
module_attr_tables = [table for table in module_macro_attr_tables if not table['isMacro']]
expanded_tables = expand_all_macros(module_attr_tables, id_to_table)
Expand Down
3 changes: 1 addition & 2 deletions dicom_standard/process_ciod_func_group_macro_relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import sys

from dicom_standard import parse_lib as pl

from process_ciod_module_relationship import expand_conditional_statement
from dicom_standard.process_ciod_module_relationship import expand_conditional_statement


# Standard workaround: Remove "Macro" from "Frame VOI LUT With LUT Macro" in Table A.84.3.2-1
Expand Down
3 changes: 1 addition & 2 deletions dicom_standard/process_macro_attribute_relationship.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys

from dicom_standard import parse_lib as pl

from process_module_attribute_relationship import get_standard_link
from dicom_standard.process_module_attribute_relationship import get_standard_link


def macro_attr_relationship_table(macro_attr_list):
Expand Down
2 changes: 1 addition & 1 deletion dicom_standard/process_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dicom_standard import parse_lib as pl

from process_modules import modules_from_tables
from dicom_standard.process_modules import modules_from_tables


if __name__ == '__main__':
Expand Down

0 comments on commit dfc9b06

Please sign in to comment.