3939
4040from os .path import relpath as path_relpath
4141from pathlib import Path as pathlib_Path
42+ from sys import version_info
4243from typing import Dict , Union , Optional as Nullable , List , Iterable , Generator , Tuple , Any as typing_Any , Type , Set , Any
4344
45+ from pyTooling .Common import getFullyQualifiedName
4446from pyTooling .Decorators import export
4547from pyTooling .MetaClasses import ExtendedType
4648from pyTooling .Graph import Graph , Vertex
@@ -123,9 +125,9 @@ class File(metaclass=FileType, slots=True):
123125 def __init__ (
124126 self ,
125127 path : pathlib_Path ,
126- project : ' Project' = None ,
127- design : ' Design' = None ,
128- fileSet : ' FileSet' = None
128+ project : Nullable [ " Project" ] = None ,
129+ design : Nullable [ " Design" ] = None ,
130+ fileSet : Nullable [ " FileSet" ] = None
129131 ):
130132 self ._fileType = getattr (FileTypes , self .__class__ .__name__ )
131133 self ._path = path
@@ -266,7 +268,12 @@ def __getitem__(self, key: Type[Attribute]) -> Any:
266268 try :
267269 return self ._attributes [key ]
268270 except KeyError :
269- return key .resolve (self , key )
271+ try :
272+ return key .resolve (self , key )
273+ except KeyError :
274+ attribute = key ()
275+ self ._attributes [key ] = attribute
276+ return attribute
270277
271278 def __setitem__ (self , key : Type [Attribute ], value : typing_Any ) -> None :
272279 """
@@ -405,7 +412,7 @@ class VHDLSourceFile(HDLSourceFile, HumanReadableContent):
405412 _vhdlLibrary : Nullable ['VHDLLibrary' ]
406413 _vhdlVersion : VHDLVersion
407414
408- def __init__ (self , path : pathlib_Path , vhdlLibrary : Union [str , 'VHDLLibrary' ] = None , vhdlVersion : VHDLVersion = None , project : ' Project' = None , design : ' Design' = None , fileSet : ' FileSet' = None ):
415+ def __init__ (self , path : pathlib_Path , vhdlLibrary : Union [str , 'VHDLLibrary' ] = None , vhdlVersion : Nullable [ VHDLVersion ] = None , project : Nullable [ " Project" ] = None , design : Nullable [ " Design" ] = None , fileSet : Nullable [ " FileSet" ] = None ):
409416 super ().__init__ (path , project , design , fileSet )
410417
411418 if isinstance (vhdlLibrary , str ):
@@ -427,7 +434,10 @@ def __init__(self, path: pathlib_Path, vhdlLibrary: Union[str, 'VHDLLibrary'] =
427434 elif vhdlLibrary is None :
428435 self ._vhdlLibrary = None
429436 else :
430- raise TypeError (f"Parameter 'vhdlLibrary' is neither a 'str' nor 'VHDLibrary'." )
437+ ex = TypeError (f"Parameter 'vhdlLibrary' is neither a 'str' nor 'VHDLibrary'." )
438+ if version_info >= (3 , 11 ): # pragma: no cover
439+ ex .add_note (f"Got type '{ getFullyQualifiedName (vhdlLibrary )} '." )
440+ raise ex
431441
432442 self ._vhdlVersion = vhdlVersion
433443
@@ -513,7 +523,7 @@ def SVVersion(self, value: SystemVerilogVersion) -> None:
513523class VerilogBaseFile (HDLSourceFile , HumanReadableContent ):
514524 _version : SystemVerilogVersion
515525
516- def __init__ (self , path : pathlib_Path , version : SystemVerilogVersion = None , project : ' Project' = None , design : ' Design' = None , fileSet : ' FileSet' = None ):
526+ def __init__ (self , path : pathlib_Path , version : Nullable [ SystemVerilogVersion ] = None , project : Nullable [ " Project" ] = None , design : Nullable [ " Design" ] = None , fileSet : Nullable [ " FileSet" ] = None ):
517527 super ().__init__ (path , project , design , fileSet )
518528
519529 self ._version = version
@@ -550,7 +560,7 @@ class SystemRDLSourceFile(RDLSourceFile, HumanReadableContent):
550560
551561 _srdlVersion : SystemRDLVersion
552562
553- def __init__ (self , path : pathlib_Path , srdlVersion : SystemRDLVersion = None , project : ' Project' = None , design : ' Design' = None , fileSet : ' FileSet' = None ):
563+ def __init__ (self , path : pathlib_Path , srdlVersion : Nullable [ SystemRDLVersion ] = None , project : Nullable [ " Project" ] = None , design : Nullable [ " Design" ] = None , fileSet : Nullable [ " FileSet" ] = None ):
554564 super ().__init__ (path , project , design , fileSet )
555565
556566 self ._srdlVersion = srdlVersion
@@ -684,16 +694,16 @@ class FileSet(metaclass=ExtendedType, slots=True):
684694 def __init__ (
685695 self ,
686696 name : str ,
687- topLevel : str = None ,
688- directory : pathlib_Path = pathlib_Path ("." ),
689- project : ' Project' = None ,
690- design : ' Design' = None ,
691- parent : Nullable ['FileSet' ] = None ,
692- vhdlLibrary : Union [str , 'VHDLLibrary' ] = None ,
693- vhdlVersion : VHDLVersion = None ,
694- verilogVersion : SystemVerilogVersion = None ,
695- svVersion : SystemVerilogVersion = None ,
696- srdlVersion : SystemRDLVersion = None
697+ topLevel : Nullable [ str ] = None ,
698+ directory : pathlib_Path = pathlib_Path ("." ),
699+ project : Nullable [ " Project" ] = None ,
700+ design : Nullable [ " Design" ] = None ,
701+ parent : Nullable ['FileSet' ] = None ,
702+ vhdlLibrary : Union [str , 'VHDLLibrary' ] = None ,
703+ vhdlVersion : Nullable [ VHDLVersion ] = None ,
704+ verilogVersion : Nullable [ SystemVerilogVersion ] = None ,
705+ svVersion : Nullable [ SystemVerilogVersion ] = None ,
706+ srdlVersion : Nullable [ SystemRDLVersion ] = None
697707 ):
698708 self ._name = name
699709 self ._topLevel = topLevel
@@ -902,11 +912,13 @@ def AddFile(self, file: File) -> None:
902912 raise TypeError ("Parameter 'file' is not of type ProjectModel.File." )
903913 elif file ._fileSet is not None :
904914 ex = ValueError (f"File '{ file .Path !s} ' is already part of fileset '{ file .FileSet .Name } '." )
905- ex .add_note (f"A file can't be assigned to another fileset." )
915+ if version_info >= (3 , 11 ): # pragma: no cover
916+ ex .add_note (f"A file can't be assigned to another fileset." )
906917 raise ex
907918 elif file in self ._set :
908919 ex = ValueError (f"File '{ file .Path !s} ' is already part of this fileset." )
909- ex .add_note (f"A file can't be added twice to a fileset." )
920+ if version_info >= (3 , 11 ): # pragma: no cover
921+ ex .add_note (f"A file can't be added twice to a fileset." )
910922 raise ex
911923
912924 self ._files .append (file )
@@ -1127,9 +1139,9 @@ class VHDLLibrary(metaclass=ExtendedType, slots=True):
11271139 def __init__ (
11281140 self ,
11291141 name : str ,
1130- project : ' Project' = None ,
1131- design : ' Design' = None ,
1132- vhdlVersion : VHDLVersion = None
1142+ project : Nullable [ " Project" ] = None ,
1143+ design : Nullable [ " Design" ] = None ,
1144+ vhdlVersion : Nullable [ VHDLVersion ] = None
11331145 ):
11341146 self ._name = name
11351147 if project is not None :
@@ -1236,7 +1248,10 @@ def AddDependency(self, library: 'VHDLLibrary') -> None:
12361248
12371249 def AddFile (self , vhdlFile : VHDLSourceFile ) -> None :
12381250 if not isinstance (vhdlFile , VHDLSourceFile ):
1239- raise TypeError (f"Parameter 'vhdlFile' is not a 'VHDLSourceFile'." )
1251+ ex = TypeError (f"Parameter 'vhdlFile' is not a 'VHDLSourceFile'." )
1252+ if version_info >= (3 , 11 ): # pragma: no cover
1253+ ex .add_note (f"Got type '{ getFullyQualifiedName (vhdlFile )} '." )
1254+ raise ex
12401255
12411256 self ._files .append (vhdlFile )
12421257
@@ -1344,13 +1359,13 @@ class Design(metaclass=ExtendedType, slots=True):
13441359 def __init__ (
13451360 self ,
13461361 name : str ,
1347- topLevel : str = None ,
1348- directory : pathlib_Path = pathlib_Path ("." ),
1349- project : ' Project' = None ,
1350- vhdlVersion : VHDLVersion = None ,
1351- verilogVersion : SystemVerilogVersion = None ,
1352- svVersion : SystemVerilogVersion = None ,
1353- srdlVersion : SystemRDLVersion = None
1362+ topLevel : Nullable [ str ] = None ,
1363+ directory : pathlib_Path = pathlib_Path ("." ),
1364+ project : Nullable [ " Project" ] = None ,
1365+ vhdlVersion : Nullable [ VHDLVersion ] = None ,
1366+ verilogVersion : Nullable [ SystemVerilogVersion ] = None ,
1367+ svVersion : Nullable [ SystemVerilogVersion ] = None ,
1368+ srdlVersion : Nullable [ SystemRDLVersion ] = None
13541369 ):
13551370 self ._name = name
13561371 self ._topLevel = topLevel
@@ -1687,10 +1702,10 @@ class Project(metaclass=ExtendedType, slots=True):
16871702 def __init__ (
16881703 self ,
16891704 name : str ,
1690- rootDirectory : pathlib_Path = pathlib_Path ("." ),
1691- vhdlVersion : VHDLVersion = None ,
1692- verilogVersion : SystemVerilogVersion = None ,
1693- svVersion : SystemVerilogVersion = None
1705+ rootDirectory : pathlib_Path = pathlib_Path ("." ),
1706+ vhdlVersion : Nullable [ VHDLVersion ] = None ,
1707+ verilogVersion : Nullable [ SystemVerilogVersion ] = None ,
1708+ svVersion : Nullable [ SystemVerilogVersion ] = None
16941709 ):
16951710 self ._name = name
16961711 self ._rootDirectory = rootDirectory
0 commit comments