-
Notifications
You must be signed in to change notification settings - Fork 62
ModelicaSystem - remove xml_file as class variable #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ents * fix some type hint issues in setInput() * prepare for definition via dictionary replacing 'a=b' and '[a=b, c=d]' style
* rename from setMethodHelper() * use _prepare_inputdata() * cleanup code to align with new input as dict[str, str] * setInput() is a special case
* replace eval() with ast.literal_eval() as a saver version * use _prepare_input_data() * simplify code
This method is used to set input values. It can be called with a sequence of input name and assigning corresponding values as arguments as show in the example below. Compared to other set*() methods this is a special case as value could be a list of tuples - these are converted to a string in _prepare_input_data() and restored here via ast.literal_eval().
read the file content and work on this string see: https://stackoverflow.com/questions/647071/python-xml-elementtree-from-a-string-source
f431876
to
c80d31d
Compare
@ondras12345 do you have an idea why the last commit is needed to make mypy happy? on my local checks there was no problem; I do not understand the background of the error in line 1528: |
OMPython/OMPython/ModelicaSystem.py Line 1481 in f958964
Here, n is a str. Its scope is not limited to that for loop, so it still exists when you get here:OMPython/OMPython/ModelicaSystem.py Lines 1523 to 1528 in f958964
mypy does not know the type of result , so it assumes it is compatible with the previous (inferred) type of n . And when you try to pass that to LinearizationResult , it gives you the
This is my best guess. It looks like there is now an option in mypy to allow variable redefinition, but I'm not sure if it would help in this case. If you want to try it, add this to
|
@ondras12345 Thanks for your analyses - I now also see the problem in the usage of However, did you notice, that current master (3e9c55b) does pass mypy without error and commit f958964 from this PR fails? There are no changes in this part of the code! I plan to update this PR to include PR #321 - it removes the first use of OMPython/OMPython/ModelicaSystem.py Lines 1478 to 1482 in f958964
will be changed to
|
… this code (int or str)
c80d31d
to
3ba84ab
Compare
Even with PR #321 this needed some additional checks as the variable
and
See commit 3ba84ab |
No idea why this is happening. We specify an exact version of mypy, so it shouldn't be that the new CI run pulled a newer version: OMPython/.pre-commit-config.yaml Lines 29 to 30 in 3e9c55b
And we use OMPython/.github/workflows/Test.yml Lines 38 to 39 in 3e9c55b
so it should check all files in each run. |
I don't think it's worth doing renames like this just to please mypy. If |
The rename is not the only point of the commit / PR #321 - it does change other parts of the code at the same place and the rename is just an additional modification at the same point |
cleanup handling of the xml file & remove another class variable
preparation for OMCPath (PR #317)
needs also PR #321