@@ -373,46 +373,47 @@ def size(self) -> int:
373373 return path .stat ().st_size
374374
375375
376- if sys .version_info < (3 , 12 ):
376+ class OMPathCompatibility (pathlib .Path ):
377+ """
378+ Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
379+ ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
380+ OMPathCompatibility is based on the standard pathlib.Path implementation.
381+ """
382+
383+ # modified copy of pathlib.Path.__new__() definition
384+ def __new__ (cls , * args , ** kwargs ):
385+ logger .warning ("Python < 3.12 - using a version of class OMCPath "
386+ "based on pathlib.Path for local usage only." )
377387
378- class _OMCPathCompatibility (pathlib .Path ):
388+ if cls is OMPathCompatibility :
389+ cls = OMPathCompatibilityWindows if os .name == 'nt' else OMPathCompatibilityPosix
390+ self = cls ._from_parts (args )
391+ if not self ._flavour .is_supported :
392+ raise NotImplementedError (f"cannot instantiate { cls .__name__ } on your system" )
393+ return self
394+
395+ def size (self ) -> int :
379396 """
380- Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
381- ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
382- _OMCPathCompatibility is based on the standard pathlib.Path implementation.
397+ Needed compatibility function to have the same interface as OMCPathReal
383398 """
399+ return self .stat ().st_size
384400
385- # modified copy of pathlib.Path.__new__() definition
386- def __new__ (cls , * args , ** kwargs ):
387- logger .warning ("Python < 3.12 - using a version of class OMCPath "
388- "based on pathlib.Path for local usage only." )
389401
390- if cls is _OMCPathCompatibility :
391- cls = _OMCPathCompatibilityWindows if os .name == 'nt' else _OMCPathCompatibilityPosix
392- self = cls ._from_parts (args )
393- if not self ._flavour .is_supported :
394- raise NotImplementedError (f"cannot instantiate { cls .__name__ } on your system" )
395- return self
396-
397- def size (self ) -> int :
398- """
399- Needed compatibility function to have the same interface as OMCPathReal
400- """
401- return self .stat ().st_size
402+ class OMPathCompatibilityPosix (pathlib .PosixPath , OMPathCompatibility ):
403+ """
404+ Compatibility class for OMCPath on Posix systems (Python < 3.12)
405+ """
402406
403- class _OMCPathCompatibilityPosix (pathlib .PosixPath , _OMCPathCompatibility ):
404- """
405- Compatibility class for OMCPath on Posix systems (Python < 3.12)
406- """
407407
408- class _OMCPathCompatibilityWindows (pathlib .WindowsPath , _OMCPathCompatibility ):
409- """
410- Compatibility class for OMCPath on Windows systems (Python < 3.12)
411- """
408+ class OMPathCompatibilityWindows (pathlib .WindowsPath , OMPathCompatibility ):
409+ """
410+ Compatibility class for OMCPath on Windows systems (Python < 3.12)
411+ """
412412
413- OMCPath = _OMCPathCompatibility
414- OMCPathDummy = _OMCPathCompatibility
415413
414+ if sys .version_info < (3 , 12 ):
415+ OMCPath = OMPathCompatibility
416+ OMCPathDummy = OMPathCompatibility
416417else :
417418 OMCPath = _OMCPath
418419 OMCPathDummy = _OMPathRunner
0 commit comments