Skip to content

Commit

Permalink
Type-hint all __init__s
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannis-vm committed May 19, 2024
1 parent 3baf76c commit 2d819d0
Show file tree
Hide file tree
Showing 34 changed files with 99 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pelicun/assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Assessment:
'loss',
]

def __init__(self, config_options: dict[str, Any] | None = None) -> None:
def __init__(self, config_options: dict[str, Any] | None = None):
"""
Initializes an Assessment object.
Expand Down
1 change: 1 addition & 0 deletions pelicun/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"""

from __future__ import annotations
import sys
import importlib
from pathlib import Path
Expand Down
19 changes: 15 additions & 4 deletions pelicun/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"""

from __future__ import annotations
from typing import Any
from typing import TYPE_CHECKING
from collections.abc import Callable
import os
import sys
Expand All @@ -84,6 +86,9 @@
from colorama import Style
from pelicun.warnings import PelicunWarning

if TYPE_CHECKING:
from pelicun.assessment import Assessment


colorama.init()
# set printing options
Expand Down Expand Up @@ -164,7 +169,11 @@ class Options:
"""

def __init__(self, user_config_options, assessment=None):
def __init__(
self,
user_config_options: dict[str, Any] | None,
assessment: Assessment | None = None,
):
"""
Initializes an Options object.
Expand Down Expand Up @@ -275,7 +284,9 @@ class Logger:
"""

def __init__(self, verbose, log_show_ms, log_file, print_log):
def __init__(
self, verbose: bool, log_show_ms: bool, log_file: str | None, print_log: bool
):
"""
Initializes a Logger object.
Expand Down Expand Up @@ -312,8 +323,8 @@ def __init__(self, verbose, log_show_ms, log_file, print_log):
raise

self.print_log = str2bool(print_log)
self.warning_stack = []
self.emitted = set()
self.warning_stack: list[str] = []
self.emitted: set[str] = set()
self.reset_log_strings()
control_warnings()

Expand Down
2 changes: 1 addition & 1 deletion pelicun/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ def create_Hazus_HU_fragility_db(
'damage_DB_SimCenter_Hazus_HU_bldg_template.json'
),
target_meta_file: str = 'damage_DB_SimCenter_Hazus_HU_bldg.json',
) -> None:
):
"""
Create a database metadata file for the HAZUS Hurricane fragilities.
Expand Down
1 change: 1 addition & 0 deletions pelicun/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"""

from __future__ import annotations
from pathlib import Path
import numpy as np
import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions pelicun/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

# flake8: noqa

from __future__ import annotations
from pelicun.model.pelicun_model import PelicunModel
from pelicun.model.demand_model import DemandModel
from pelicun.model.asset_model import AssetModel
Expand Down
6 changes: 5 additions & 1 deletion pelicun/model/asset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"""

from __future__ import annotations
from typing import TYPE_CHECKING
from itertools import product
import numpy as np
import pandas as pd
Expand All @@ -57,6 +59,8 @@
from pelicun import uq
from pelicun import file_io

if TYPE_CHECKING:
from pelicun.assessment import Assessment

idx = base.idx

Expand All @@ -72,7 +76,7 @@ class AssetModel(PelicunModel):

__slots__ = ['cmp_marginal_params', 'cmp_units', 'cmp_sample', '_cmp_RVs']

def __init__(self, assessment):
def __init__(self, assessment: Assessment):
super().__init__(assessment)

self.cmp_marginal_params = None
Expand Down
6 changes: 3 additions & 3 deletions pelicun/model/damage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DamageModel(PelicunModel):

__slots__ = ['ds_model', 'missing_components']

def __init__(self, assessment: Assessment) -> None:
def __init__(self, assessment: Assessment):
super().__init__(assessment)

self.ds_model: DamageModel_DS = DamageModel_DS(assessment)
Expand Down Expand Up @@ -417,7 +417,7 @@ class DamageModel_Base(PelicunModel):

__slots__ = ['damage_params', 'sample']

def __init__(self, assessment):
def __init__(self, assessment: Assessment):
super().__init__(assessment)

self.damage_params = None
Expand Down Expand Up @@ -629,7 +629,7 @@ class DamageModel_DS(DamageModel_Base):

__slots__ = ['ds_sample']

def __init__(self, assessment):
def __init__(self, assessment: Assessment):
super().__init__(assessment)
self.ds_sample = None

Expand Down
6 changes: 5 additions & 1 deletion pelicun/model/demand_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@
"""

from __future__ import annotations
from typing import TYPE_CHECKING
import numpy as np
import pandas as pd
from pelicun.model.pelicun_model import PelicunModel
from pelicun import base
from pelicun import uq
from pelicun import file_io

if TYPE_CHECKING:
from pelicun.assessment import Assessment

idx = base.idx

Expand Down Expand Up @@ -103,7 +107,7 @@ class DemandModel(PelicunModel):
'sample',
]

def __init__(self, assessment):
def __init__(self, assessment: Assessment):
super().__init__(assessment)

self.marginal_params = None
Expand Down
4 changes: 2 additions & 2 deletions pelicun/model/loss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(
self,
assessment: Assessment,
decision_variables: list[str] = ['Carbon', 'Cost', 'Energy', 'Time'],
) -> None:
):
"""
Initializes LossModel objects.
Expand Down Expand Up @@ -763,7 +763,7 @@ class RepairModel_Base(PelicunModel):

__slots__ = ['loss_params', 'sample', 'consequence']

def __init__(self, assessment):
def __init__(self, assessment: Assessment):
"""
Initializes RepairModel_Base objects.
Expand Down
2 changes: 1 addition & 1 deletion pelicun/model/pelicun_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PelicunModel:

__slots__ = ['_asmnt', 'log']

def __init__(self, assessment: Assessment) -> None:
def __init__(self, assessment: Assessment):
# link the PelicunModel object to its Assessment object
self._asmnt: Assessment = assessment

Expand Down
1 change: 1 addition & 0 deletions pelicun/resources/auto/Hazus_Earthquake_IM.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#
# Contributors:
# Adam Zsarnóczay
from __future__ import annotations
import json
import pandas as pd
import pelicun
Expand Down
1 change: 1 addition & 0 deletions pelicun/resources/auto/Hazus_Earthquake_Story.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Contributors:
# Adam Zsarnóczay

from __future__ import annotations
import pandas as pd

ap_DesignLevel = {1940: 'LC', 1975: 'MC', 2100: 'HC'}
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/code_repetition_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Python test files.
"""

from __future__ import annotations
from glob2 import glob # type: ignore

# pylint: disable=missing-any-param-doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from __future__ import annotations
import numpy as np
import pandas as pd
from pelicun.base import convert_to_MultiIndex
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_asset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the asset model of pelicun.
"""

from __future__ import annotations
import tempfile
from copy import deepcopy
import pytest
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_damage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the damage model of pelicun.
"""

from __future__ import annotations
from copy import deepcopy
import warnings
import pytest
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_demand_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the demand model of pelicun.
"""

from __future__ import annotations
import os
import tempfile
import warnings
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_loss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the loss model of pelicun.
"""

from __future__ import annotations
from itertools import product
from copy import deepcopy
import pytest
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
This file defines a clas used by the model unit tests.
"""

from __future__ import annotations
from copy import deepcopy
import pytest
from pelicun import assessment
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/model/test_pelicun_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the PelicunModel class.
"""

from __future__ import annotations
from copy import deepcopy
import pytest
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/reset_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
This file is used to reset all expected test result data.
"""

from __future__ import annotations
import os
import re
import glob
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/test_assessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the assessment module of pelicun.
"""

from __future__ import annotations
import pytest
from pelicun import assessment

Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"""

from __future__ import annotations
from unittest.mock import patch
from unittest.mock import MagicMock
import pytest
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the base module of pelicun.
"""

from __future__ import annotations
import os
import io
import re
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are unit and integration tests on the file_io module of pelicun.
"""

from __future__ import annotations
import tempfile
import os
import pytest
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/test_uq.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
reset from the `reset_all_test_data` function in `reset_tests.py`.
"""

from __future__ import annotations
import warnings
import pytest
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
These are utility functions for the unit and integration tests.
"""

from __future__ import annotations
import pickle
import os

Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/validation/0/test_loss_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"""

from __future__ import annotations
import numpy as np
import pandas as pd
import pelicun
Expand Down
1 change: 1 addition & 0 deletions pelicun/tests/validation/1/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"""

from __future__ import annotations
import tempfile
import numpy as np
import pandas as pd
Expand Down
1 change: 1 addition & 0 deletions pelicun/tools/DL_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Contributors:
# Adam Zsarnóczay

from __future__ import annotations
from time import gmtime
from time import strftime
import sys
Expand Down
1 change: 1 addition & 0 deletions pelicun/tools/HDF_to_CSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Contributors:
# Adam Zsarnóczay

from __future__ import annotations
import pandas as pd
import sys
import argparse
Expand Down
1 change: 1 addition & 0 deletions pelicun/tools/export_DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Contributors:
# Adam Zsarnóczay

from __future__ import annotations
import sys
import json
import argparse
Expand Down
Loading

0 comments on commit 2d819d0

Please sign in to comment.