Skip to content

Commit

Permalink
Improved type hints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jun 8, 2024
1 parent 6235bee commit 0e10580
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 124 deletions.
2 changes: 1 addition & 1 deletion pyVHDLModel/Association.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def Formal(self) -> Nullable[Symbol]: # TODO: can also be a conversion function
def Actual(self) -> ExpressionUnion:
return self._actual

def __str__(self):
def __str__(self) -> str:
if self._formal is None:
return str(self._actual)
else:
Expand Down
14 changes: 7 additions & 7 deletions pyVHDLModel/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Direction(Enum):
To = 0 #: Ascending direction
DownTo = 1 #: Descending direction

def __str__(self):
def __str__(self) -> str:
"""
Formats the direction to ``to`` or ``downto``.
Expand All @@ -88,7 +88,7 @@ class Mode(Enum):
Buffer = 4 #: Buffered output
Linkage = 5 #: undocumented

def __str__(self):
def __str__(self) -> str:
"""
Formats the direction.
Expand All @@ -109,7 +109,7 @@ class ModelEntity(metaclass=ExtendedType, slots=True):

_parent: 'ModelEntity' #: Reference to a parent entity in the model.

def __init__(self):
def __init__(self) -> None:
"""Initializes a VHDL model entity."""
self._parent = None

Expand Down Expand Up @@ -285,7 +285,7 @@ class ConditionalMixin(metaclass=ExtendedType, mixin=True):

_condition: ExpressionUnion

def __init__(self, condition: ExpressionUnion = None):
def __init__(self, condition: ExpressionUnion = None) -> None:
self._condition = condition
if condition is not None:
condition._parent = self
Expand All @@ -299,7 +299,7 @@ def Condition(self) -> ExpressionUnion:
class BranchMixin(metaclass=ExtendedType, mixin=True):
"""A ``BaseBranch`` is a mixin-class for all statements with branches."""

def __init__(self):
def __init__(self) -> None:
pass


Expand Down Expand Up @@ -333,7 +333,7 @@ class ReportStatementMixin(metaclass=ExtendedType, mixin=True):
_message: Nullable[ExpressionUnion]
_severity: Nullable[ExpressionUnion]

def __init__(self, message: ExpressionUnion = None, severity: ExpressionUnion = None):
def __init__(self, message: ExpressionUnion = None, severity: ExpressionUnion = None) -> None:
self._message = message
if message is not None:
message._parent = self
Expand Down Expand Up @@ -363,7 +363,7 @@ def __init__(self, condition: ExpressionUnion, message: ExpressionUnion = None,
class BlockStatementMixin(metaclass=ExtendedType, mixin=True):
"""A ``BlockStatement`` is a mixin-class for all block statements."""

def __init__(self):
def __init__(self) -> None:
pass


Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Statement(ModelEntity, LabeledEntityMixin):
"""
A ``Statement`` is a base-class for all statements.
"""
def __init__(self, label: str = None):
def __init__(self, label: str = None) -> None:
super().__init__()
LabeledEntityMixin.__init__(self, label)

Expand Down
6 changes: 3 additions & 3 deletions pyVHDLModel/Concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def IterateInstantiations(self) -> Generator['Instantiation', None, None]:
yield from generate.IterateInstantiations()

# TODO: move into _init__
def IndexStatements(self):
def IndexStatements(self) -> None:
for statement in self._statements:
if isinstance(statement, (EntityInstantiation, ComponentInstantiation, ConfigurationInstantiation)):
self._instantiations[statement.NormalizedLabel] = statement
Expand Down Expand Up @@ -450,7 +450,7 @@ class GenerateStatement(ConcurrentStatement):

_namespace: Namespace

def __init__(self, label: str = None):
def __init__(self, label: str = None) -> None:
super().__init__(label)

self._namespace = Namespace(self._normalizedLabel)
Expand Down Expand Up @@ -664,7 +664,7 @@ def IterateInstantiations(self) -> Generator[Instantiation, None, None]:
for case in self._cases:
yield from case.IterateInstantiations()

def IndexStatement(self):
def IndexStatement(self) -> None:
for case in self._cases:
case.IndexStatements()

Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, identifier: str, subtype: Symbol, documentation: str = None):
subtype._parent = self

@property
def Subtype(self):
def Subtype(self) -> None:
return self._subtype


Expand Down
4 changes: 2 additions & 2 deletions pyVHDLModel/DesignUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def PackageReferences(self) -> List[UseClause]:
def ContextReferences(self) -> List[ContextReference]:
return self._contextReferences

def __str__(self):
def __str__(self) -> str:
lib = self._library.Identifier + "?" if self._library is not None else ""

return f"Context: {lib}.{self._identifier}"
Expand Down Expand Up @@ -482,7 +482,7 @@ def Package(self) -> PackageSymbol:
def DeclaredItems(self) -> List:
return self._declaredItems

def LinkDeclaredItemsToPackage(self):
def LinkDeclaredItemsToPackage(self) -> None:
pass

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class VHDLModelException(Exception):
# Implementing a dummy method for Python versions before
__notes__: List[str]
if version_info < (3, 11): # pragma: no cover
def add_note(self, message: str):
def add_note(self, message: str) -> None:
try:
self.__notes__.append(message)
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ class TernaryExpression(BaseExpression):
_secondOperand: ExpressionUnion
_thirdOperand: ExpressionUnion

def __init__(self):
def __init__(self) -> None:
super().__init__()

# FIXME: parameters and initializers are missing !!
Expand Down
34 changes: 17 additions & 17 deletions pyVHDLModel/IEEE.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class Ieee(PredefinedLibrary):
* Library :class:`~pyVHDLModel.STD.Std`
"""

def __init__(self):
def __init__(self) -> None:
super().__init__(PACKAGES)

def LoadSynopsysPackages(self):
def LoadSynopsysPackages(self) -> None:
self.AddPackages(PACKAGES_SYNOPSYS)


Expand All @@ -106,7 +106,7 @@ class Math_Complex(PredefinedPackage):
Predefined package ``ieee.math_complex``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("work.math_real.all",))
Expand All @@ -118,7 +118,7 @@ class Math_Complex_Body(PredefinedPackageBody):
Predefined package body of package ``ieee.math_complex``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("work.math_real.all",))
Expand All @@ -135,7 +135,7 @@ class Std_logic_1164(PredefinedPackage):
* ``std_logic``, ``std_logic_vector``
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand Down Expand Up @@ -182,7 +182,7 @@ class std_logic_textio(PredefinedPackage):
Predefined package ``ieee.std_logic_textio``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand All @@ -196,7 +196,7 @@ class Std_logic_misc(PredefinedPackage):
Predefined package ``ieee.std_logic_misc``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -216,7 +216,7 @@ class Numeric_Bit(PredefinedPackage):
Predefined package ``ieee.numeric_bit``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand All @@ -242,7 +242,7 @@ class Numeric_Bit_Unsigned_Body(PredefinedPackageBody):
Predefined package body of package ``ieee.numeric_bit_unsigned``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -260,7 +260,7 @@ class Numeric_Std(PredefinedPackage):
* ``unresolved_signed``, ``signed``
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand Down Expand Up @@ -299,7 +299,7 @@ class Numeric_Std_Unsigned(PredefinedPackage):
Predefined package ``ieee.numeric_std_unsigned``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -312,7 +312,7 @@ class Numeric_Std_Unsigned_Body(PredefinedPackageBody):
Predefined package body of package ``ieee.numeric_std_unsigned``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -332,7 +332,7 @@ class Fixed_Generic_Pkg(PredefinedPackage):
Predefined package ``ieee.fixed_generic_pkg``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand All @@ -348,7 +348,7 @@ class Fixed_Generic_Pkg_Body(PredefinedPackageBody):
Predefined package body of package ``ieee.fixed_generic_pkg``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -360,7 +360,7 @@ class Fixed_Pkg(PredefinedPackage):
"""
Predefined package ``ieee.fixed_pkg``.
"""
def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand All @@ -372,7 +372,7 @@ class Float_Generic_Pkg(PredefinedPackage):
Predefined package ``ieee.float_generic_pkg``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddPackageClause(("STD.TEXTIO.all", ))
Expand All @@ -395,7 +395,7 @@ class Float_Pkg(PredefinedPackage):
Predefined package ``ieee.float_pkg``.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__()

self._AddLibraryClause(("IEEE", ))
Expand Down
6 changes: 3 additions & 3 deletions pyVHDLModel/Instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@

@export
class GenericInstantiationMixin(metaclass=ExtendedType, mixin=True):
def __init__(self):
def __init__(self) -> None:
pass


@export
class GenericEntityInstantiationMixin(GenericInstantiationMixin, mixin=True):
def __init__(self):
def __init__(self) -> None:
pass


@export
class SubprogramInstantiationMixin(GenericInstantiationMixin, mixin=True):
_subprogramReference: Subprogram # FIXME: is this a subprogram symbol?

def __init__(self):
def __init__(self) -> None:
super().__init__()
self._subprogramReference = None

Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
class InterfaceItemMixin(DocumentedEntityMixin, mixin=True):
"""An ``InterfaceItem`` is a base-class for all mixin-classes for all interface items."""

def __init__(self, documentation: str = None):
def __init__(self, documentation: str = None) -> None:
super().__init__(documentation)


Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Name.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class OpenName(Name):
Most likely this name is used in port associations.
"""
def __init__(self):
def __init__(self) -> None:
super().__init__("open") # TODO: the case of 'ALL' is not preserved

def __str__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyVHDLModel/Object.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class WithDefaultExpressionMixin(metaclass=ExtendedType, mixin=True):

_defaultExpression: Nullable[ExpressionUnion]

def __init__(self, defaultExpression: ExpressionUnion = None):
def __init__(self, defaultExpression: ExpressionUnion = None) -> None:
self._defaultExpression = defaultExpression
if defaultExpression is not None:
defaultExpression._parent = self
Expand Down
6 changes: 3 additions & 3 deletions pyVHDLModel/Predefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, packages):

self.AddPackages(packages)

def AddPackages(self, packages):
def AddPackages(self, packages) -> None:
for packageType, packageBodyType in packages:
package: Package = packageType()
package.Library = self
Expand Down Expand Up @@ -104,7 +104,7 @@ class PredefinedPackage(Package, PredefinedPackageMixin):
A base-class for predefined VHDL packages.
"""

def __init__(self):
def __init__(self) -> None:
super().__init__(self.__class__.__name__)


Expand All @@ -114,6 +114,6 @@ class PredefinedPackageBody(PackageBody, PredefinedPackageMixin):
A base-class for predefined VHDL package bodies.
"""

def __init__(self):
def __init__(self) -> None:
packageSymbol = PackageSymbol(SimpleName(self.__class__.__name__[:-5]))
super().__init__(packageSymbol)
Loading

0 comments on commit 0e10580

Please sign in to comment.