Skip to content

Commit

Permalink
Added Nullable to parameter typehints if default is None.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jul 1, 2024
1 parent 7c01493 commit 2f3a98b
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 109 deletions.
2 changes: 1 addition & 1 deletion pyVHDLModel/Association.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AssociationItem(ModelEntity):
_formal: Nullable[Symbol]
_actual: ExpressionUnion

def __init__(self, actual: ExpressionUnion, formal: Symbol = None):
def __init__(self, actual: ExpressionUnion, formal: Nullable[Symbol] = None):
super().__init__()

self._formal = formal
Expand Down
8 changes: 4 additions & 4 deletions pyVHDLModel/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class ConditionalMixin(metaclass=ExtendedType, mixin=True):

_condition: ExpressionUnion

def __init__(self, condition: ExpressionUnion = None) -> None:
def __init__(self, condition: Nullable[ExpressionUnion] = None) -> None:
self._condition = condition
if condition is not None:
condition._parent = self
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) -> None:
def __init__(self, message: Nullable[ExpressionUnion] = None, severity: Nullable[ExpressionUnion] = None) -> None:
self._message = message
if message is not None:
message._parent = self
Expand All @@ -355,7 +355,7 @@ def Severity(self) -> Nullable[ExpressionUnion]:
class AssertStatementMixin(ReportStatementMixin, ConditionalMixin, mixin=True):
"""A ``MixinAssertStatement`` is a mixin-class for all assert statements."""

def __init__(self, condition: ExpressionUnion, message: ExpressionUnion = None, severity: ExpressionUnion = None):
def __init__(self, condition: ExpressionUnion, message: Nullable[ExpressionUnion] = None, severity: Nullable[ExpressionUnion] = None):
super().__init__(message, severity)
ConditionalMixin.__init__(self, condition)

Expand Down Expand Up @@ -417,7 +417,7 @@ class WaveformElement(ModelEntity):
_expression: ExpressionUnion
_after: ExpressionUnion

def __init__(self, expression: ExpressionUnion, after: ExpressionUnion = None):
def __init__(self, expression: ExpressionUnion, after: Nullable[ExpressionUnion] = None):
super().__init__()

self._expression = expression
Expand Down
6 changes: 3 additions & 3 deletions pyVHDLModel/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Common definitions and Mixins are used by many classes in the model as base-classes.
"""
from typing import List, Iterable, Union
from typing import List, Iterable, Union, Optional as Nullable

from pyTooling.Decorators import export
from pyTooling.MetaClasses import ExtendedType
Expand All @@ -60,7 +60,7 @@ class Statement(ModelEntity, LabeledEntityMixin):
"""
A ``Statement`` is a base-class for all statements.
"""
def __init__(self, label: str = None) -> None:
def __init__(self, label: Nullable[str] = None) -> None:
super().__init__()
LabeledEntityMixin.__init__(self, label)

Expand All @@ -70,7 +70,7 @@ class ProcedureCallMixin(metaclass=ExtendedType, mixin=True):
_procedure: Symbol # TODO: implement a ProcedureSymbol
_parameterMappings: List[ParameterAssociationItem]

def __init__(self, procedureName: Symbol, parameterMappings: Iterable[ParameterAssociationItem] = None):
def __init__(self, procedureName: Symbol, parameterMappings: Nullable[Iterable[ParameterAssociationItem]] = None):
self._procedure = procedureName
procedureName._parent = self

Expand Down
48 changes: 24 additions & 24 deletions pyVHDLModel/Concurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ConcurrentStatementsMixin(metaclass=ExtendedType, mixin=True):
_generates: Dict[str, 'GenerateStatement']
_hierarchy: Dict[str, Union['ConcurrentBlockStatement', 'GenerateStatement']]

def __init__(self, statements: Iterable[ConcurrentStatement] = None):
def __init__(self, statements: Nullable[Iterable[ConcurrentStatement]] = None):
self._statements = []

self._instantiations = {}
Expand Down Expand Up @@ -133,7 +133,7 @@ class Instantiation(ConcurrentStatement):
_genericAssociations: List[AssociationItem]
_portAssociations: List[AssociationItem]

def __init__(self, label: str, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None):
def __init__(self, label: str, genericAssociations: Nullable[Iterable[AssociationItem]] = None, portAssociations: Nullable[Iterable[AssociationItem]] = None):
super().__init__(label)

# TODO: extract to mixin
Expand Down Expand Up @@ -173,7 +173,7 @@ class ComponentInstantiation(Instantiation):

_component: ComponentInstantiationSymbol

def __init__(self, label: str, componentSymbol: ComponentInstantiationSymbol, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None):
def __init__(self, label: str, componentSymbol: ComponentInstantiationSymbol, genericAssociations: Nullable[Iterable[AssociationItem]] = None, portAssociations: Nullable[Iterable[AssociationItem]] = None):
super().__init__(label, genericAssociations, portAssociations)

self._component = componentSymbol
Expand All @@ -199,7 +199,7 @@ class EntityInstantiation(Instantiation):
_entity: EntityInstantiationSymbol
_architecture: ArchitectureSymbol

def __init__(self, label: str, entitySymbol: EntityInstantiationSymbol, architectureSymbol: ArchitectureSymbol = None, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None):
def __init__(self, label: str, entitySymbol: EntityInstantiationSymbol, architectureSymbol: Nullable[ArchitectureSymbol] = None, genericAssociations: Nullable[Iterable[AssociationItem]] = None, portAssociations: Nullable[Iterable[AssociationItem]] = None):
super().__init__(label, genericAssociations, portAssociations)

self._entity = entitySymbol
Expand Down Expand Up @@ -232,7 +232,7 @@ class ConfigurationInstantiation(Instantiation):

_configuration: ConfigurationInstantiationSymbol

def __init__(self, label: str, configurationSymbol: ConfigurationInstantiationSymbol, genericAssociations: Iterable[AssociationItem] = None, portAssociations: Iterable[AssociationItem] = None):
def __init__(self, label: str, configurationSymbol: ConfigurationInstantiationSymbol, genericAssociations: Nullable[Iterable[AssociationItem]] = None, portAssociations: Nullable[Iterable[AssociationItem]] = None):
super().__init__(label, genericAssociations, portAssociations)

self._configuration = configurationSymbol
Expand Down Expand Up @@ -263,11 +263,11 @@ class ProcessStatement(ConcurrentStatement, SequentialDeclarationsMixin, Sequent

def __init__(
self,
label: str = None,
declaredItems: Iterable = None,
statements: Iterable[SequentialStatement] = None,
sensitivityList: Iterable[Name] = None,
documentation: str = None
label: Nullable[str] = None,
declaredItems: Nullable[Iterable] = None,
statements: Nullable[Iterable[SequentialStatement]] = None,
sensitivityList: Nullable[Iterable[Name]] = None,
documentation: Nullable[str] = None
):
super().__init__(label)
SequentialDeclarationsMixin.__init__(self, declaredItems)
Expand All @@ -289,7 +289,7 @@ def SensitivityList(self) -> List[Name]:

@export
class ConcurrentProcedureCall(ConcurrentStatement, ProcedureCallMixin):
def __init__(self, label: str, procedureName: Name, parameterMappings: Iterable[ParameterAssociationItem] = None):
def __init__(self, label: str, procedureName: Name, parameterMappings: Nullable[Iterable[ParameterAssociationItem]] = None):
super().__init__(label)
ProcedureCallMixin.__init__(self, procedureName, parameterMappings)

Expand All @@ -301,10 +301,10 @@ class ConcurrentBlockStatement(ConcurrentStatement, BlockStatementMixin, Labeled
def __init__(
self,
label: str,
portItems: Iterable[PortInterfaceItemMixin] = None,
declaredItems: Iterable = None,
portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None,
declaredItems: Nullable[Iterable] = None,
statements: Iterable['ConcurrentStatement'] = None,
documentation: str = None
documentation: Nullable[str] = None
):
super().__init__(label)
BlockStatementMixin.__init__(self)
Expand Down Expand Up @@ -342,7 +342,7 @@ class GenerateBranch(ModelEntity, ConcurrentDeclarationRegionMixin, ConcurrentSt

_namespace: Namespace

def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__()
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatementsMixin.__init__(self, statements)
Expand Down Expand Up @@ -381,7 +381,7 @@ class IfGenerateBranch(GenerateBranch, IfBranchMixin):
end generate;
"""

def __init__(self, condition: ExpressionUnion, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, condition: ExpressionUnion, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__(declaredItems, statements, alternativeLabel)
IfBranchMixin.__init__(self, condition)

Expand All @@ -406,7 +406,7 @@ class ElsifGenerateBranch(GenerateBranch, ElsifBranchMixin):
end generate;
"""

def __init__(self, condition: ExpressionUnion, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, condition: ExpressionUnion, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__(declaredItems, statements, alternativeLabel)
ElsifBranchMixin.__init__(self, condition)

Expand All @@ -431,7 +431,7 @@ class ElseGenerateBranch(GenerateBranch, ElseBranchMixin):
end generate;
"""

def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__(declaredItems, statements, alternativeLabel)
ElseBranchMixin.__init__(self)

Expand All @@ -450,7 +450,7 @@ class GenerateStatement(ConcurrentStatement):

_namespace: Namespace

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

self._namespace = Namespace(self._normalizedLabel)
Expand Down Expand Up @@ -493,7 +493,7 @@ class IfGenerateStatement(GenerateStatement):
_elsifBranches: List[ElsifGenerateBranch]
_elseBranch: Nullable[ElseGenerateBranch]

def __init__(self, label: str, ifBranch: IfGenerateBranch, elsifBranches: Iterable[ElsifGenerateBranch] = None, elseBranch: ElseGenerateBranch = None):
def __init__(self, label: str, ifBranch: IfGenerateBranch, elsifBranches: Nullable[Iterable[ElsifGenerateBranch]] = None, elseBranch: Nullable[ElseGenerateBranch] = None):
super().__init__(label)

self._ifBranch = ifBranch
Expand Down Expand Up @@ -581,7 +581,7 @@ def __str__(self) -> str:

@export
class ConcurrentCase(BaseCase, LabeledEntityMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin):
def __init__(self, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__()
LabeledEntityMixin.__init__(self, alternativeLabel)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
Expand All @@ -592,7 +592,7 @@ def __init__(self, declaredItems: Iterable = None, statements: Iterable[Concurre
class GenerateCase(ConcurrentCase):
_choices: List[ConcurrentChoice]

def __init__(self, choices: Iterable[ConcurrentChoice], declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None, alternativeLabel: str = None):
def __init__(self, choices: Iterable[ConcurrentChoice], declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None, alternativeLabel: Nullable[str] = None):
super().__init__(declaredItems, statements, alternativeLabel)

# TODO: move to parent or grandparent
Expand Down Expand Up @@ -686,7 +686,7 @@ class ForGenerateStatement(GenerateStatement, ConcurrentDeclarationRegionMixin,
_loopIndex: str
_range: Range

def __init__(self, label: str, loopIndex: str, rng: Range, declaredItems: Iterable = None, statements: Iterable[ConcurrentStatement] = None):
def __init__(self, label: str, loopIndex: str, rng: Range, declaredItems: Nullable[Iterable] = None, statements: Nullable[Iterable[ConcurrentStatement]] = None):
super().__init__(label)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
ConcurrentStatementsMixin.__init__(self, statements)
Expand Down Expand Up @@ -765,6 +765,6 @@ def __init__(self, label: str, target: Name, expression: ExpressionUnion):

@export
class ConcurrentAssertStatement(ConcurrentStatement, AssertStatementMixin):
def __init__(self, condition: ExpressionUnion, message: ExpressionUnion, severity: ExpressionUnion = None, label: str = None):
def __init__(self, condition: ExpressionUnion, message: ExpressionUnion, severity: Nullable[ExpressionUnion] = None, label: Nullable[str] = None):
super().__init__(label)
AssertStatementMixin.__init__(self, condition, message, severity)
8 changes: 4 additions & 4 deletions pyVHDLModel/Declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"""
from enum import unique, Enum
from typing import List, Iterable, Union
from typing import List, Iterable, Union, Optional as Nullable

from pyTooling.Decorators import export

Expand Down Expand Up @@ -98,7 +98,7 @@ class Attribute(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):

_subtype: Symbol

def __init__(self, identifier: str, subtype: Symbol, documentation: str = None):
def __init__(self, identifier: str, subtype: Symbol, documentation: Nullable[str] = None):
super().__init__()
NamedEntityMixin.__init__(self, identifier)
DocumentedEntityMixin.__init__(self, documentation)
Expand Down Expand Up @@ -128,7 +128,7 @@ class AttributeSpecification(ModelEntity, DocumentedEntityMixin):
_entityClass: EntityClass
_expression: ExpressionUnion

def __init__(self, identifiers: Iterable[Name], attribute: Name, entityClass: EntityClass, expression: ExpressionUnion, documentation: str = None):
def __init__(self, identifiers: Iterable[Name], attribute: Name, entityClass: EntityClass, expression: ExpressionUnion, documentation: Nullable[str] = None):
super().__init__()
DocumentedEntityMixin.__init__(self, documentation)

Expand Down Expand Up @@ -165,7 +165,7 @@ def Expression(self) -> ExpressionUnion:
# TODO: move somewhere else
@export
class Alias(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):
def __init__(self, identifier: str, documentation: str = None):
def __init__(self, identifier: str, documentation: Nullable[str] = None):
"""
Initializes underlying ``BaseType``.
Expand Down
26 changes: 13 additions & 13 deletions pyVHDLModel/DesignUnit.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class DesignUnit(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):

_namespace: 'Namespace'

def __init__(self, identifier: str, contextItems: Iterable[ContextUnion] = None, documentation: str = None):
def __init__(self, identifier: str, contextItems: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None):
"""
Initializes a design unit.
Expand Down Expand Up @@ -340,7 +340,7 @@ class Context(PrimaryUnit):

_references: List[ContextUnion]

def __init__(self, identifier: str, references: Iterable[ContextUnion] = None, documentation: str = None):
def __init__(self, identifier: str, references: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None):
super().__init__(identifier, None, documentation)

self._references = []
Expand Down Expand Up @@ -399,7 +399,7 @@ class Package(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegi
_deferredConstants: Dict[str, DeferredConstant]
_components: Dict[str, 'Component']

def __init__(self, identifier: str, contextItems: Iterable[ContextUnion] = None, genericItems: Iterable[GenericInterfaceItemMixin] = None, declaredItems: Iterable = None, documentation: str = None):
def __init__(self, identifier: str, contextItems: Nullable[Iterable[ContextUnion]] = None, genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, declaredItems: Nullable[Iterable] = None, documentation: Nullable[str] = None):
super().__init__(identifier, contextItems, documentation)
DesignUnitWithContextMixin.__init__(self)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
Expand Down Expand Up @@ -466,7 +466,7 @@ class PackageBody(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarati

_package: PackageSymbol

def __init__(self, packageSymbol: PackageSymbol, contextItems: Iterable[ContextUnion] = None, declaredItems: Iterable = None, documentation: str = None):
def __init__(self, packageSymbol: PackageSymbol, contextItems: Nullable[Iterable[ContextUnion]] = None, declaredItems: Nullable[Iterable] = None, documentation: Nullable[str] = None):
super().__init__(packageSymbol.Name.Identifier, contextItems, documentation)
DesignUnitWithContextMixin.__init__(self)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
Expand Down Expand Up @@ -518,12 +518,12 @@ class Entity(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegio
def __init__(
self,
identifier: str,
contextItems: Iterable[ContextUnion] = None,
genericItems: Iterable[GenericInterfaceItemMixin] = None,
portItems: Iterable[PortInterfaceItemMixin] = None,
declaredItems: Iterable = None,
statements: Iterable[ConcurrentStatement] = None,
documentation: str = None
contextItems: Nullable[Iterable[ContextUnion]] = None,
genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None,
portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None,
declaredItems: Nullable[Iterable] = None,
statements: Nullable[Iterable[ConcurrentStatement]] = None,
documentation: Nullable[str] = None
):
super().__init__(identifier, contextItems, documentation)
DesignUnitWithContextMixin.__init__(self)
Expand Down Expand Up @@ -591,7 +591,7 @@ class Architecture(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarat

_entity: EntitySymbol

def __init__(self, identifier: str, entity: EntitySymbol, contextItems: Iterable[Context] = None, declaredItems: Iterable = None, statements: Iterable['ConcurrentStatement'] = None, documentation: str = None):
def __init__(self, identifier: str, entity: EntitySymbol, contextItems: Nullable[Iterable[Context]] = None, declaredItems: Nullable[Iterable] = None, statements: Iterable['ConcurrentStatement'] = None, documentation: Nullable[str] = None):
super().__init__(identifier, contextItems, documentation)
DesignUnitWithContextMixin.__init__(self)
ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
Expand Down Expand Up @@ -645,7 +645,7 @@ class Component(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):

_entity: Nullable[Entity]

def __init__(self, identifier: str, genericItems: Iterable[GenericInterfaceItemMixin] = None, portItems: Iterable[PortInterfaceItemMixin] = None, documentation: str = None):
def __init__(self, identifier: str, genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None, documentation: Nullable[str] = None):
super().__init__()
NamedEntityMixin.__init__(self, identifier)
DocumentedEntityMixin.__init__(self, documentation)
Expand Down Expand Up @@ -697,7 +697,7 @@ class Configuration(PrimaryUnit, DesignUnitWithContextMixin):
end configuration;
"""

def __init__(self, identifier: str, contextItems: Iterable[Context] = None, documentation: str = None):
def __init__(self, identifier: str, contextItems: Nullable[Iterable[Context]] = None, documentation: Nullable[str] = None):
super().__init__(identifier, contextItems, documentation)
DesignUnitWithContextMixin.__init__(self)

Expand Down
Loading

0 comments on commit 2f3a98b

Please sign in to comment.