Skip to content

Commit e83ca0b

Browse files
committed
Type and doc cleanup
1 parent 91be728 commit e83ca0b

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

cmdstanpy/cmdstan_args.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class CmdStanArgs:
632632
def __init__(
633633
self,
634634
model_name: str,
635-
model_exe: Union[os.PathLike, str],
635+
model_exe: str,
636636
chain_ids: Optional[list[int]],
637637
method_args: Union[
638638
SamplerArgs,
@@ -853,10 +853,10 @@ def compose_command(
853853
idx, len(self.chain_ids)
854854
)
855855
)
856-
cmd.append(self.model_exe) # type: ignore # guaranteed by validate
856+
cmd.append(self.model_exe)
857857
cmd.append(f'id={self.chain_ids[idx]}')
858858
else:
859-
cmd.append(self.model_exe) # type: ignore # guaranteed by validate
859+
cmd.append(self.model_exe)
860860

861861
if self.seed is not None:
862862
if not isinstance(self.seed, list):

cmdstanpy/compilation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def compile_stan_file(
441441
raise ValueError(
442442
f"Failed to compile Stan model '{src}'. Console:\n{console}"
443443
)
444-
return str(exe_target)
444+
return os.fspath(exe_target)
445445

446446

447447
def format_stan_file(

cmdstanpy/model.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ class CmdStanModel:
6868
Stan program source file or the compiled executable, or both.
6969
This will compile the model if provided a Stan file and no executable,
7070
71-
:param model_name: Model name, used for output file names.
72-
Optional, default is the base filename of the Stan program file.
73-
Deprecated: In version 2.0.0, model name cannot be
74-
specified and will always be taken from executable.
75-
7671
:param stan_file: Path to Stan program file.
7772
7873
:param exe_file: Path to compiled executable file. Optional, unless
@@ -94,13 +89,6 @@ class CmdStanModel:
9489
:param user_header: A path to a header file to include during C++
9590
compilation.
9691
Optional.
97-
98-
:param compile: Whether or not to compile the model. Default is ``True``.
99-
If set to the string ``"force"``, it will always compile even if
100-
an existing executable is found.
101-
Deprecated: Use ``force_compile`` instead. The ability to instantiate
102-
a CmdStanModel without an executable will be removed in version 2.0.0.
103-
10492
"""
10593

10694
def __init__(
@@ -115,7 +103,6 @@ def __init__(
115103
"""
116104
Initialize object given constructor args.
117105
118-
:param model_name: Deprecated. Model name, used for output file names.
119106
:param stan_file: Path to Stan program file.
120107
:param exe_file: Path to compiled executable file.
121108
:param force_compile: Whether or not to force recompilation if
@@ -206,17 +193,15 @@ def __init__(
206193
get_logger().debug("TBB already found in load path")
207194

208195
def __repr__(self) -> str:
209-
repr = 'CmdStanModel: name={}'.format(self._name)
210-
repr = '{}\n\t stan_file={}'.format(repr, self._stan_file)
211-
repr = '{}\n\t exe_file={}'.format(repr, self._exe_file)
212-
return repr
196+
return (
197+
f"CmdStanModel(stan_file={self.stan_file!r}, "
198+
f"exe_file={self.exe_file!r})"
199+
)
213200

214201
@property
215202
def name(self) -> str:
216203
"""
217-
Model name used in output filename templates. Default is basename
218-
of Stan program or exe file, unless specified in call to constructor
219-
via argument ``model_name``.
204+
Model name used in output filename templates.
220205
"""
221206
return self._name
222207

@@ -226,7 +211,7 @@ def stan_file(self) -> OptionalPath:
226211
return self._stan_file
227212

228213
@property
229-
def exe_file(self) -> Union[os.PathLike, str]:
214+
def exe_file(self) -> str:
230215
"""Full path to Stan exe file."""
231216
return self._exe_file
232217

@@ -237,7 +222,7 @@ def exe_info(self) -> dict[str, str]:
237222
"""
238223
result: dict[str, str] = {}
239224
info = StringIO()
240-
do_command(cmd=[str(self.exe_file), 'info'], fd_out=info)
225+
do_command(cmd=[self.exe_file, 'info'], fd_out=info)
241226
lines = info.getvalue().split('\n')
242227
for line in lines:
243228
kv_pair = [x.strip() for x in line.split('=')]

test/test_model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ def test_model_syntax_error() -> None:
344344

345345
def test_repr() -> None:
346346
model = CmdStanModel(stan_file=BERN_STAN)
347-
model_repr = repr(model)
348-
assert 'name=bernoulli' in model_repr
347+
assert BERN_STAN in repr(model)
349348

350349

351350
def test_print() -> None:

0 commit comments

Comments
 (0)