From cfc0cccbb6123da37621e8eb63d5736f734ad368 Mon Sep 17 00:00:00 2001 From: trevorb1 Date: Sun, 31 Mar 2024 10:08:11 -0700 Subject: [PATCH] upgrade to mypy 1.9.0 --- .pre-commit-config.yaml | 2 +- src/otoole/convert.py | 5 +++-- src/otoole/read_strategies.py | 2 +- src/otoole/utils.py | 4 ++-- src/otoole/validate.py | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a270cf8d..edb7dc51 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -53,7 +53,7 @@ repos: ## You can add flake8 plugins via `additional_dependencies`: # additional_dependencies: [flake8-bugbear] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.961 # Use the sha / tag you want to point at + rev: v1.9.0 # Use the sha / tag you want to point at hooks: - id: mypy additional_dependencies: ['types-PyYAML'] diff --git a/src/otoole/convert.py b/src/otoole/convert.py index 3cecd343..4267ac79 100644 --- a/src/otoole/convert.py +++ b/src/otoole/convert.py @@ -7,6 +7,7 @@ >>> convert('config.yaml', 'excel', 'datafile', 'input.xlsx', 'output.dat') """ + import logging import os from typing import Dict, Optional, Tuple, Union @@ -29,7 +30,7 @@ def read_results( from_path: str, input_format: str, input_path: str, - glpk_model: str = None, + glpk_model: Optional[str] = None, ) -> Tuple[Dict[str, pd.DataFrame], Dict[str, float]]: """Read OSeMOSYS results from CBC, GLPK, Gurobi, or CPLEX results files @@ -79,7 +80,7 @@ def convert_results( input_format: str, input_path: str, write_defaults: bool = False, - glpk_model: str = None, + glpk_model: Optional[str] = None, ) -> bool: """Post-process results from a CBC, CPLEX, Gurobi, or GLPK solution file into CSV format diff --git a/src/otoole/read_strategies.py b/src/otoole/read_strategies.py index 7f5805c6..da362cea 100644 --- a/src/otoole/read_strategies.py +++ b/src/otoole/read_strategies.py @@ -33,7 +33,7 @@ def __init__( self._parameters = parameters def read( - self, filepath: Union[str, TextIO] = None, **kwargs + self, filepath: Union[str, TextIO, None] = None, **kwargs ) -> Tuple[Dict[str, pd.DataFrame], Dict[str, Any]]: config = self.user_config diff --git a/src/otoole/utils.py b/src/otoole/utils.py index d5308ca4..fe989b7e 100644 --- a/src/otoole/utils.py +++ b/src/otoole/utils.py @@ -2,7 +2,7 @@ import logging import os from importlib.resources import files -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union import pandas as pd from pydantic import ValidationError @@ -29,7 +29,7 @@ def _read_file(open_file, ending): return contents -def read_packaged_file(filename: str, module_name: str = None): +def read_packaged_file(filename: str, module_name: Optional[str] = None): _, ending = os.path.splitext(filename) diff --git a/src/otoole/validate.py b/src/otoole/validate.py index f889bf71..3c39257d 100644 --- a/src/otoole/validate.py +++ b/src/otoole/validate.py @@ -33,7 +33,7 @@ import logging import re from collections import defaultdict -from typing import Dict, List, Sequence +from typing import Dict, List, Optional, Sequence import networkx.algorithms.isolate as isolate import pandas as pd @@ -53,7 +53,7 @@ def check_for_duplicates(codes: Sequence) -> bool: return duplicate_values -def create_schema(config: Dict[str, Dict] = None) -> Dict: +def create_schema(config: Optional[Dict[str, Dict]] = None) -> Dict: """Populate the dict of schema with codes from the validation config Arguments