1111from copy import copy
1212from datetime import datetime
1313from pathlib import Path
14- from typing import Any , Dict , Iterable , List , Optional , Union
14+ from typing import Any , Iterable , Optional , Union
1515
1616from cmdstanpy .utils import get_logger
1717from cmdstanpy .utils .cmdstan import (
@@ -81,8 +81,8 @@ class CompilerOptions:
8181 def __init__ (
8282 self ,
8383 * ,
84- stanc_options : Optional [Dict [str , Any ]] = None ,
85- cpp_options : Optional [Dict [str , Any ]] = None ,
84+ stanc_options : Optional [dict [str , Any ]] = None ,
85+ cpp_options : Optional [dict [str , Any ]] = None ,
8686 user_header : OptionalPath = None ,
8787 ) -> None :
8888 """Initialize object."""
@@ -116,12 +116,12 @@ def is_empty(self) -> bool:
116116 )
117117
118118 @property
119- def stanc_options (self ) -> Dict [str , Union [bool , int , str , Iterable [str ]]]:
119+ def stanc_options (self ) -> dict [str , Union [bool , int , str , Iterable [str ]]]:
120120 """Stanc compiler options."""
121121 return self ._stanc_options
122122
123123 @property
124- def cpp_options (self ) -> Dict [str , Union [bool , int ]]:
124+ def cpp_options (self ) -> dict [str , Union [bool , int ]]:
125125 """C++ compiler options."""
126126 return self ._cpp_options
127127
@@ -165,8 +165,7 @@ def validate_stanc_opts(self) -> None:
165165 del self ._stanc_options [deprecated ]
166166 else :
167167 get_logger ().warning (
168- 'compiler option "%s" is deprecated and '
169- 'should not be used' ,
168+ 'compiler option "%s" is deprecated and should not be used' ,
170169 deprecated ,
171170 )
172171 for key , val in self ._stanc_options .items ():
@@ -225,8 +224,7 @@ def validate_cpp_opts(self) -> None:
225224 val = self ._cpp_options [key ]
226225 if not isinstance (val , int ) or val < 0 :
227226 raise ValueError (
228- f'{ key } must be a non-negative integer value,'
229- f' found { val } .'
227+ f'{ key } must be a non-negative integer value, found { val } .'
230228 )
231229
232230 def validate_user_header (self ) -> None :
@@ -236,8 +234,7 @@ def validate_user_header(self) -> None:
236234 """
237235 if self ._user_header != "" :
238236 if not (
239- os .path .exists (self ._user_header )
240- and os .path .isfile (self ._user_header )
237+ os .path .exists (self ._user_header ) and os .path .isfile (self ._user_header )
241238 ):
242239 raise ValueError (
243240 f"User header file { self ._user_header } cannot be found"
@@ -275,9 +272,7 @@ def add(self, new_opts: "CompilerOptions") -> None: # noqa: disable=Q000
275272 else :
276273 for key , val in new_opts .stanc_options .items ():
277274 if key == 'include-paths' :
278- if isinstance (val , Iterable ) and not isinstance (
279- val , str
280- ):
275+ if isinstance (val , Iterable ) and not isinstance (val , str ):
281276 for path in val :
282277 self .add_include_path (str (path ))
283278 else :
@@ -298,7 +293,7 @@ def add_include_path(self, path: str) -> None:
298293 elif path not in self ._stanc_options ['include-paths' ]:
299294 self ._stanc_options ['include-paths' ].append (path )
300295
301- def compose_stanc (self , filename_in_msg : Optional [str ]) -> List [str ]:
296+ def compose_stanc (self , filename_in_msg : Optional [str ]) -> list [str ]:
302297 opts = []
303298
304299 if filename_in_msg is not None :
@@ -322,7 +317,7 @@ def compose_stanc(self, filename_in_msg: Optional[str]) -> List[str]:
322317 opts .append (f'--{ key } ' )
323318 return opts
324319
325- def compose (self , filename_in_msg : Optional [str ] = None ) -> List [str ]:
320+ def compose (self , filename_in_msg : Optional [str ] = None ) -> list [str ]:
326321 """
327322 Format makefile options as list of strings.
328323
@@ -342,9 +337,7 @@ def compose(self, filename_in_msg: Optional[str] = None) -> List[str]:
342337 return opts
343338
344339
345- def src_info (
346- stan_file : str , compiler_options : CompilerOptions
347- ) -> Dict [str , Any ]:
340+ def src_info (stan_file : str , compiler_options : CompilerOptions ) -> dict [str , Any ]:
348341 """
349342 Get source info for Stan program file.
350343
@@ -363,15 +356,15 @@ def src_info(
363356 f"Failed to get source info for Stan model "
364357 f"'{ stan_file } '. Console:\n { proc .stderr } "
365358 )
366- result : Dict [str , Any ] = json .loads (proc .stdout )
359+ result : dict [str , Any ] = json .loads (proc .stdout )
367360 return result
368361
369362
370363def compile_stan_file (
371364 src : Union [str , Path ],
372365 force : bool = False ,
373- stanc_options : Optional [Dict [str , Any ]] = None ,
374- cpp_options : Optional [Dict [str , Any ]] = None ,
366+ stanc_options : Optional [dict [str , Any ]] = None ,
367+ cpp_options : Optional [dict [str , Any ]] = None ,
375368 user_header : OptionalPath = None ,
376369) -> str :
377370 """
@@ -480,7 +473,7 @@ def compile_stan_file(
480473 "If the issue persists please open a bug report"
481474 )
482475 raise ValueError (
483- f"Failed to compile Stan model '{ src } '. " f" Console:\n { console } "
476+ f"Failed to compile Stan model '{ src } '. Console:\n { console } "
484477 )
485478 return str (exe_target )
486479
@@ -492,7 +485,7 @@ def format_stan_file(
492485 canonicalize : Union [bool , str , Iterable [str ]] = False ,
493486 max_line_length : int = 78 ,
494487 backup : bool = True ,
495- stanc_options : Optional [Dict [str , Any ]] = None ,
488+ stanc_options : Optional [dict [str , Any ]] = None ,
496489) -> None :
497490 """
498491 Run stanc's auto-formatter on the model code. Either saves directly
@@ -532,9 +525,7 @@ def format_stan_file(
532525 else :
533526 raise ValueError (
534527 "Invalid arguments passed for current CmdStan"
535- + " version({})\n " .format (
536- cmdstan_version () or "Unknown"
537- )
528+ + " version({})\n " .format (cmdstan_version () or "Unknown" )
538529 + "--canonicalize requires 2.29 or higher"
539530 )
540531 else :
0 commit comments