Skip to content

Commit

Permalink
Update type hints and docstrings for file importing
Browse files Browse the repository at this point in the history
  • Loading branch information
proy30 committed Jan 7, 2025
1 parent f617fef commit 35a9900
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/python/impactx/dashboard/Toolbar/importParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DashboardParser:
to the dashboard and auto-populate the UI with their configurations.
"""

def file_details(file):
def file_details(file) -> None:

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'file', as their first parameter.
"""
Displays the size of the imported simulation file.
Expand All @@ -33,12 +33,11 @@ def file_details(file):

state.import_file_details = f"({size_str}) {file['name']}"

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'size_str' may be used before it is initialized.

def parse_impactx_simulation_file(file):
def parse_impactx_simulation_file(file) -> None:

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'file', as their first parameter.
"""
Parses ImpactX simulation file contents.
:param file: ImpactX simulation file uploaded by the user.
:return: A dictionary containing the parsed inputs.
"""

file_content = DashboardParserHelper.import_file_content(file)
Expand All @@ -59,9 +58,9 @@ def parse_impactx_simulation_file(file):

return parsed_values_dictionary

def populate_impactx_simulation_file_to_ui(file):
def populate_impactx_simulation_file_to_ui(file) -> None:

Check notice

Code scanning / CodeQL

First parameter of a method is not named 'self' Note

Normal methods should have 'self', rather than 'file', as their first parameter.
"""
Function populates the ImpactX dashboard UI.
Auto fills the dashboard with parsed inputs.
:param file: ImpactX simulation file uploaded by the user.
"""
Expand Down
20 changes: 10 additions & 10 deletions src/python/impactx/dashboard/Toolbar/importParserHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class DashboardParserHelper:
"""

@staticmethod
def import_file_content(file):
def import_file_content(file: str) -> dict:
"""
Retrieves and prints the content of the uploaded simulation file.
:param content: The content of the ImpactX simulation file as a string.
:param content: The content of the ImpactX simulation file.
"""
if file:
content = file["content"].decode("utf-8")
Expand All @@ -27,11 +27,11 @@ def import_file_content(file):
return ""

@staticmethod
def parse_single_inputs(content):
def parse_single_inputs(content: str) -> dict:
"""
Parses individual input parameters from the simulation file content.
:param content: The content of the ImpactX simulation file as a string.
:param content: The content of the ImpactX simulation file.
"""
reference_dictionary = DashboardDefaults.DEFAULT_VALUES.copy()

Expand Down Expand Up @@ -62,11 +62,11 @@ def parse_single_inputs(content):
return reference_dictionary

@staticmethod
def parse_list_inputs(content):
def parse_list_inputs(content: str) -> dict:
"""
Parses list-based input parameters from the simulation file content.
:param content: The content of the ImpactX simulation file as a string.
:param content: The content of the ImpactX simulation file.
"""
dictionary = {}
list_inputs = ["n_cell", "prob_relative"]
Expand All @@ -87,11 +87,11 @@ def parse_list_inputs(content):
return dictionary

@staticmethod
def parse_distribution(content):
def parse_distribution(content: str) -> dict:
"""
Parses distribution section from the simulation file content.
:param content: The content of the ImpactX simulation file as a string.
:param content: The content of the ImpactX simulation file.
"""

dictionary = {"distribution": {"name": "", "type": "", "parameters": {}}}
Expand Down Expand Up @@ -130,11 +130,11 @@ def extract_parameters(distribution_type, parsing_pattern):
return dictionary

@staticmethod
def parse_lattice_elements(content):
def parse_lattice_elements(content: str) -> dict:
"""
Parses lattice elements from the simulation file content.
:param content: The content of the ImpactX simulation file as a string.
:param content: The content of the ImpactX simulation file.
"""

dictionary = {"lattice_elements": []}
Expand Down

0 comments on commit 35a9900

Please sign in to comment.