[OMCSession*] Cleanup / mypy check#291
Conversation
| self._dockerOpenModelicaPath = dockerOpenModelicaPath | ||
| self._dockerNetwork = dockerNetwork | ||
| self._create_omc_log_file("port") | ||
| self._omc_log_file = self._create_omc_log_file("port") |
There was a problem hiding this comment.
Isn't the best practice is generally to set the value of a member variable directly within a member function?
There was a problem hiding this comment.
This is a good question - I'm not sure; my reasoning is as follows but if there are different views I'm fine with it - but this would mean to rewrite this PR for some parts ...
- an internal / private function is used (starting with '_')
- within these class functions all class members can be accessed (but should not be changed)
- I tried to put the definition of class members via return value and set the value in init() as it is quite visible this way
- furthermore, it is required to set / define class variables in init()
- at the end, these helper functions are just cutouts from init() to make it better readable
There was a problem hiding this comment.
- an internal / private function is used (starting with '_')
That is fine.
- within these class functions all class members can be accessed (but should not be changed)
- I tried to put the definition of class members via return value and set the value in init() as it is quite visible this way
- furthermore, it is required to set / define class variables in init()
- at the end, these helper functions are just cutouts from init() to make it better readable
You can't enforce this programmatically. It is still possible to access the member with a dot notation. It is like we are expecting the current/future developers will follow these guidelines.
I think the pythonic way to handle this is to use the python property https://docs.python.org/3/library/functions.html#property. If we do this, the users/developers can still access the class member with dot notation but a getter/setter is always called so we know from where the value of a member is set or accessed.
There was a problem hiding this comment.
I thing using property would be the way to go if there is a need to enforce this. Here, it is more a way to make the code more readable - class variables which are set are directly visible in __init__() with the source of the used value.
a4a0d75 to
cf937cc
Compare
fix mypy warnings in OMCSession and some additional cleanup