Skip to content

Commit 405e5b7

Browse files
committed
Fix remaining mypy errors
1 parent 02eeadb commit 405e5b7

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ repos:
3636
- pyparsing
3737
- types-psutil
3838
- pyzmq
39+
- numpy

OMPython/ModelicaSystem.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import subprocess
4646
import tempfile
4747
import textwrap
48-
from typing import Optional
48+
from typing import Optional, Any
4949
import warnings
5050
import xml.etree.ElementTree as ET
5151

@@ -369,20 +369,23 @@ def __init__(
369369
if modelName is None:
370370
raise ModelicaSystemError("A modelname must be provided (argument modelName)!")
371371

372-
self.quantitiesList = []
373-
self.paramlist = {}
374-
self.inputlist = {}
375-
self.outputlist = {}
376-
self.continuouslist = {}
377-
self.simulateOptions = {}
378-
self.overridevariables = {}
379-
self.simoptionsoverride = {}
372+
self.quantitiesList: list[dict[str, Any]] = []
373+
self.paramlist: dict[str, str] = {} # even numerical values are stored as str
374+
self.inputlist: dict[str, list | None] = {}
375+
# outputlist values are str before simulate(), but they can be
376+
# np.float64 after simulate().
377+
self.outputlist: dict[str, Any] = {}
378+
# same for continuouslist
379+
self.continuouslist: dict[str, Any] = {}
380+
self.simulateOptions: dict[str, str] = {}
381+
self.overridevariables: dict[str, str] = {}
382+
self.simoptionsoverride: dict[str, str] = {}
380383
self.linearOptions = {'startTime': 0.0, 'stopTime': 1.0, 'stepSize': 0.002, 'tolerance': 1e-8}
381384
self.optimizeOptions = {'startTime': 0.0, 'stopTime': 1.0, 'numberOfIntervals': 500, 'stepSize': 0.002,
382385
'tolerance': 1e-8}
383-
self.linearinputs = [] # linearization input list
384-
self.linearoutputs = [] # linearization output list
385-
self.linearstates = [] # linearization states list
386+
self.linearinputs: list[str] = [] # linearization input list
387+
self.linearoutputs: list[str] = [] # linearization output list
388+
self.linearstates: list[str] = [] # linearization states list
386389

387390
if session is not None:
388391
if not isinstance(session, OMCSessionZMQ):

OMPython/OMTypedParser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ def evaluateExpression(s, loc, toks):
107107
omcRecord = Forward()
108108
omcValue = Forward()
109109

110-
TRUE = Keyword("true").setParseAction(replaceWith(True))
111-
FALSE = Keyword("false").setParseAction(replaceWith(False))
112-
NONE = (Keyword("NONE") + Suppress("(") + Suppress(")")).setParseAction(replaceWith(None))
110+
# pyparsing's replace_with (and thus replaceWith) has incorrect type
111+
# annotation: https://github.com/pyparsing/pyparsing/issues/602
112+
TRUE = Keyword("true").setParseAction(replaceWith(True)) # type: ignore
113+
FALSE = Keyword("false").setParseAction(replaceWith(False)) # type: ignore
114+
NONE = (Keyword("NONE") + Suppress("(") + Suppress(")")).setParseAction(replaceWith(None)) # type: ignore
113115
SOME = (Suppress(Keyword("SOME")) + Suppress("(") + omcValue + Suppress(")"))
114116

115117
omcString = QuotedString(quoteChar='"', escChar='\\', multiline=True).setParseAction(convertString)

0 commit comments

Comments
 (0)