-
Notifications
You must be signed in to change notification settings - Fork 62
[OMCSession*] Cleanup / mypy check #291
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
Conversation
self._docker = docker | ||
self._dockerContainer = dockerContainer | ||
self._dockerExtraArgs = dockerExtraArgs | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I am fine with it.
a4a0d75
to
cf937cc
Compare
fix mypy warnings in OMCSession and some additional cleanup