Skip to content

Commit 27a49e5

Browse files
committed
G001-pylint
[pylint] fix 'R1729: Use a generator instead 'all(isinstance(item, tuple) for item in val_evaluated)' (use-a-generator)' [pylint] fix 'W0237: Parameter 'expr' has been renamed to 'command' in overriding 'OMCSessionZMQ.sendExpression' method (arguments-renamed)' [pylint] [OM*Path*] fix pylint messags about incompatible definitions
1 parent 674bb36 commit 27a49e5

File tree

5 files changed

+56
-27
lines changed

5 files changed

+56
-27
lines changed

OMPython/OMCSession.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,14 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC
282282
def execute(self, command: str):
283283
return self.omc_process.execute(command=command)
284284

285-
def sendExpression(self, command: str, parsed: bool = True) -> Any:
285+
def sendExpression(self, command: str, parsed: bool = True) -> Any: # pylint: disable=W0237
286286
"""
287287
Send an expression to the OMC server and return the result.
288288
289-
The complete error handling of the OMC result is done within this method using '"getMessagesStringInternal()'.
289+
The complete error handling of the OMC result is done within this method using 'getMessagesStringInternal()'.
290290
Caller should only check for OMCSessionException.
291+
292+
Compatibility: 'command' was renamed to 'expr'
291293
"""
292294
return self.omc_process.sendExpression(expr=command, parsed=parsed)
293295

OMPython/modelica_system_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def setInputs(
10201020
self._inputs[key] = [(float(self._simulate_options["startTime"]), float(val)),
10211021
(float(self._simulate_options["stopTime"]), float(val))]
10221022
elif isinstance(val_evaluated, list):
1023-
if not all([isinstance(item, tuple) for item in val_evaluated]):
1023+
if not all(isinstance(item, tuple) for item in val_evaluated):
10241024
raise ModelicaSystemError("Value for setInput() must be in tuple format; "
10251025
f"got {repr(val_evaluated)}")
10261026
if val_evaluated != sorted(val_evaluated, key=lambda x: x[0]):

OMPython/om_session_abc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ def with_segments(self, *pathsegments) -> OMPathABC:
9595
return type(self)(*pathsegments, session=self._session)
9696

9797
@abc.abstractmethod
98-
def is_file(self) -> bool:
98+
def is_file(self, *, follow_symlinks=True) -> bool:
9999
"""
100100
Check if the path is a regular file.
101101
"""
102102

103103
@abc.abstractmethod
104-
def is_dir(self) -> bool:
104+
def is_dir(self, *, follow_symlinks: bool = True) -> bool:
105105
"""
106106
Check if the path is a directory.
107107
"""
@@ -113,19 +113,19 @@ def is_absolute(self) -> bool:
113113
"""
114114

115115
@abc.abstractmethod
116-
def read_text(self) -> str:
116+
def read_text(self, encoding=None, errors=None, newline=None) -> str:
117117
"""
118118
Read the content of the file represented by this path as text.
119119
"""
120120

121121
@abc.abstractmethod
122-
def write_text(self, data: str) -> int:
122+
def write_text(self, data: str, encoding=None, errors=None, newline=None) -> int:
123123
"""
124124
Write text data to the file represented by this path.
125125
"""
126126

127127
@abc.abstractmethod
128-
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
128+
def mkdir(self, mode=0o777, parents: bool = False, exist_ok: bool = False) -> None:
129129
"""
130130
Create a directory at the path represented by this class.
131131
@@ -135,7 +135,7 @@ def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
135135
"""
136136

137137
@abc.abstractmethod
138-
def cwd(self) -> OMPathABC:
138+
def cwd(self) -> OMPathABC: # pylint: disable=W0221 # is @classmethod in the original; see pathlib.PathBase
139139
"""
140140
Returns the current working directory as an OMPathABC object.
141141
"""

OMPython/om_session_omc.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,23 @@ class _OMCPath(OMPathABC):
5252
OMCSession* classes.
5353
"""
5454

55-
def is_file(self) -> bool:
55+
def is_file(self, *, follow_symlinks=True) -> bool:
5656
"""
5757
Check if the path is a regular file.
5858
"""
59+
del follow_symlinks
60+
5961
retval = self.get_session().sendExpression(expr=f'regularFileExists("{self.as_posix()}")')
6062
if not isinstance(retval, bool):
6163
raise OMSessionException(f"Invalid return value for is_file(): {retval} - expect bool")
6264
return retval
6365

64-
def is_dir(self) -> bool:
66+
def is_dir(self, *, follow_symlinks: bool = True) -> bool:
6567
"""
6668
Check if the path is a directory.
6769
"""
70+
del follow_symlinks
71+
6872
retval = self.get_session().sendExpression(expr=f'directoryExists("{self.as_posix()}")')
6973
if not isinstance(retval, bool):
7074
raise OMSessionException(f"Invalid return value for is_dir(): {retval} - expect bool")
@@ -78,19 +82,23 @@ def is_absolute(self) -> bool:
7882
return pathlib.PureWindowsPath(self.as_posix()).is_absolute()
7983
return pathlib.PurePosixPath(self.as_posix()).is_absolute()
8084

81-
def read_text(self) -> str:
85+
def read_text(self, encoding=None, errors=None, newline=None) -> str:
8286
"""
8387
Read the content of the file represented by this path as text.
8488
"""
89+
del encoding, errors, newline
90+
8591
retval = self.get_session().sendExpression(expr=f'readFile("{self.as_posix()}")')
8692
if not isinstance(retval, str):
8793
raise OMSessionException(f"Invalid return value for read_text(): {retval} - expect str")
8894
return retval
8995

90-
def write_text(self, data: str) -> int:
96+
def write_text(self, data: str, encoding=None, errors=None, newline=None) -> int:
9197
"""
9298
Write text data to the file represented by this path.
9399
"""
100+
del encoding, errors, newline
101+
94102
if not isinstance(data, str):
95103
raise TypeError(f"data must be str, not {data.__class__.__name__}")
96104

@@ -99,21 +107,23 @@ def write_text(self, data: str) -> int:
99107

100108
return len(data)
101109

102-
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
110+
def mkdir(self, mode=0o777, parents: bool = False, exist_ok: bool = False) -> None:
103111
"""
104112
Create a directory at the path represented by this class.
105113
106114
The argument parents with default value True exists to ensure compatibility with the fallback solution for
107115
Python < 3.12. In this case, pathlib.Path is used directly and this option ensures, that missing parent
108116
directories are also created.
109117
"""
118+
del mode
119+
110120
if self.is_dir() and not exist_ok:
111121
raise FileExistsError(f"Directory {self.as_posix()} already exists!")
112122

113123
if not self._session.sendExpression(expr=f'mkdir("{self.as_posix()}")'):
114124
raise OMSessionException(f"Error on directory creation for {self.as_posix()}!")
115125

116-
def cwd(self) -> OMPathABC:
126+
def cwd(self) -> OMPathABC: # pylint: disable=W0221 # is @classmethod in the original; see pathlib.PathBase
117127
"""
118128
Returns the current working directory as an OMPathABC object.
119129
"""

OMPython/om_session_runner.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,20 @@ class _OMPathRunnerLocal(OMPathRunnerABC):
4949
conversion via pathlib.Path(<OMCPathDummy>.as_posix()).
5050
"""
5151

52-
def is_file(self) -> bool:
52+
def is_file(self, *, follow_symlinks=True) -> bool:
5353
"""
5454
Check if the path is a regular file.
5555
"""
56+
del follow_symlinks
57+
5658
return self._path().is_file()
5759

58-
def is_dir(self) -> bool:
60+
def is_dir(self, *, follow_symlinks: bool = True) -> bool:
5961
"""
6062
Check if the path is a directory.
6163
"""
64+
del follow_symlinks
65+
6266
return self._path().is_dir()
6367

6468
def is_absolute(self) -> bool:
@@ -67,32 +71,38 @@ def is_absolute(self) -> bool:
6771
"""
6872
return self._path().is_absolute()
6973

70-
def read_text(self) -> str:
74+
def read_text(self, encoding=None, errors=None, newline=None) -> str:
7175
"""
7276
Read the content of the file represented by this path as text.
7377
"""
78+
del encoding, errors, newline
79+
7480
return self._path().read_text(encoding='utf-8')
7581

76-
def write_text(self, data: str):
82+
def write_text(self, data: str, encoding=None, errors=None, newline=None):
7783
"""
7884
Write text data to the file represented by this path.
7985
"""
86+
del encoding, errors, newline
87+
8088
if not isinstance(data, str):
8189
raise TypeError(f"data must be str, not {data.__class__.__name__}")
8290

8391
return self._path().write_text(data=data, encoding='utf-8')
8492

85-
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
93+
def mkdir(self, mode=0o777, parents: bool = False, exist_ok: bool = False) -> None:
8694
"""
8795
Create a directory at the path represented by this class.
8896
8997
The argument parents with default value True exists to ensure compatibility with the fallback solution for
9098
Python < 3.12. In this case, pathlib.Path is used directly and this option ensures, that missing parent
9199
directories are also created.
92100
"""
101+
del mode
102+
93103
self._path().mkdir(parents=parents, exist_ok=exist_ok)
94104

95-
def cwd(self) -> OMPathABC:
105+
def cwd(self) -> OMPathABC: # pylint: disable=W0221 # is @classmethod in the original; see pathlib.PathBase
96106
"""
97107
Returns the current working directory as an OMPathABC object.
98108
"""
@@ -132,10 +142,12 @@ class _OMPathRunnerBash(OMPathRunnerABC):
132142
conversion via pathlib.Path(<OMCPathDummy>.as_posix()).
133143
"""
134144

135-
def is_file(self) -> bool:
145+
def is_file(self, *, follow_symlinks=True) -> bool:
136146
"""
137147
Check if the path is a regular file.
138148
"""
149+
del follow_symlinks
150+
139151
cmdl = self.get_session().get_cmd_prefix()
140152
cmdl += ['bash', '-c', f'test -f "{self.as_posix()}"']
141153

@@ -145,7 +157,7 @@ def is_file(self) -> bool:
145157
except subprocess.CalledProcessError:
146158
return False
147159

148-
def is_dir(self) -> bool:
160+
def is_dir(self, *, follow_symlinks: bool = True) -> bool:
149161
"""
150162
Check if the path is a directory.
151163
"""
@@ -172,10 +184,12 @@ def is_absolute(self) -> bool:
172184
except subprocess.CalledProcessError:
173185
return False
174186

175-
def read_text(self) -> str:
187+
def read_text(self, encoding=None, errors=None, newline=None) -> str:
176188
"""
177189
Read the content of the file represented by this path as text.
178190
"""
191+
del encoding, errors, newline
192+
179193
cmdl = self.get_session().get_cmd_prefix()
180194
cmdl += ['bash', '-c', f'cat "{self.as_posix()}"']
181195

@@ -184,10 +198,12 @@ def read_text(self) -> str:
184198
return result.stdout.decode('utf-8')
185199
raise FileNotFoundError(f"Cannot read file: {self.as_posix()}")
186200

187-
def write_text(self, data: str) -> int:
201+
def write_text(self, data: str, encoding=None, errors=None, newline=None) -> int:
188202
"""
189203
Write text data to the file represented by this path.
190204
"""
205+
del encoding, errors, newline
206+
191207
if not isinstance(data, str):
192208
raise TypeError(f"data must be str, not {data.__class__.__name__}")
193209

@@ -202,14 +218,15 @@ def write_text(self, data: str) -> int:
202218
except subprocess.CalledProcessError as exc:
203219
raise IOError(f"Error writing data to file {self.as_posix()}!") from exc
204220

205-
def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
221+
def mkdir(self, mode=0o777, parents: bool = False, exist_ok: bool = False) -> None:
206222
"""
207223
Create a directory at the path represented by this class.
208224
209225
The argument parents with default value True exists to ensure compatibility with the fallback solution for
210226
Python < 3.12. In this case, pathlib.Path is used directly and this option ensures, that missing parent
211227
directories are also created.
212228
"""
229+
del mode
213230

214231
if self.is_file():
215232
raise OSError(f"The given path {self.as_posix()} exists and is a file!")
@@ -226,7 +243,7 @@ def mkdir(self, parents: bool = True, exist_ok: bool = False) -> None:
226243
except subprocess.CalledProcessError as exc:
227244
raise OMSessionException(f"Error on directory creation for {self.as_posix()}!") from exc
228245

229-
def cwd(self) -> OMPathABC:
246+
def cwd(self) -> OMPathABC: # pylint: disable=W0221 # is @classmethod in the original; see pathlib.PathBase
230247
"""
231248
Returns the current working directory as an OMPathABC object.
232249
"""

0 commit comments

Comments
 (0)