From 2f3a98bc84dd120ee46465f029fb88189c943f4f Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Mon, 1 Jul 2024 23:45:59 +0200 Subject: [PATCH] Added Nullable to parameter typehints if default is None. --- pyVHDLModel/Association.py | 2 +- pyVHDLModel/Base.py | 8 +++--- pyVHDLModel/Common.py | 6 ++--- pyVHDLModel/Concurrent.py | 48 ++++++++++++++++++------------------ pyVHDLModel/Declaration.py | 8 +++--- pyVHDLModel/DesignUnit.py | 26 +++++++++---------- pyVHDLModel/Instantiation.py | 4 +-- pyVHDLModel/Interface.py | 24 +++++++++--------- pyVHDLModel/Name.py | 2 +- pyVHDLModel/Namespace.py | 4 +-- pyVHDLModel/Object.py | 12 ++++----- pyVHDLModel/Regions.py | 4 +-- pyVHDLModel/Sequential.py | 42 +++++++++++++++---------------- pyVHDLModel/Subprogram.py | 8 +++--- pyVHDLModel/Type.py | 6 ++--- pyVHDLModel/__init__.py | 4 +-- pyproject.toml | 7 ++---- 17 files changed, 106 insertions(+), 109 deletions(-) diff --git a/pyVHDLModel/Association.py b/pyVHDLModel/Association.py index a6bc89027..7927cbf24 100644 --- a/pyVHDLModel/Association.py +++ b/pyVHDLModel/Association.py @@ -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 diff --git a/pyVHDLModel/Base.py b/pyVHDLModel/Base.py index 08a2a689c..4a90fd0e6 100644 --- a/pyVHDLModel/Base.py +++ b/pyVHDLModel/Base.py @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/pyVHDLModel/Common.py b/pyVHDLModel/Common.py index 233b4b16b..daaf7b5d1 100644 --- a/pyVHDLModel/Common.py +++ b/pyVHDLModel/Common.py @@ -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 @@ -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) @@ -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 diff --git a/pyVHDLModel/Concurrent.py b/pyVHDLModel/Concurrent.py index b5aedccd6..f6bb15bb5 100644 --- a/pyVHDLModel/Concurrent.py +++ b/pyVHDLModel/Concurrent.py @@ -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 = {} @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 @@ -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) @@ -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 @@ -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) @@ -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) diff --git a/pyVHDLModel/Declaration.py b/pyVHDLModel/Declaration.py index 273878f38..aed0434ec 100644 --- a/pyVHDLModel/Declaration.py +++ b/pyVHDLModel/Declaration.py @@ -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 @@ -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) @@ -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) @@ -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``. diff --git a/pyVHDLModel/DesignUnit.py b/pyVHDLModel/DesignUnit.py index 44074f1ec..c5a2b6434 100644 --- a/pyVHDLModel/DesignUnit.py +++ b/pyVHDLModel/DesignUnit.py @@ -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. @@ -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 = [] @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/pyVHDLModel/Instantiation.py b/pyVHDLModel/Instantiation.py index 7596a894d..a7ceab9f8 100644 --- a/pyVHDLModel/Instantiation.py +++ b/pyVHDLModel/Instantiation.py @@ -34,7 +34,7 @@ Instantiations of packages, procedures, functions and protected types. """ -from typing import List +from typing import List, Optional as Nullable from pyTooling.Decorators import export from pyTooling.MetaClasses import ExtendedType @@ -82,7 +82,7 @@ class PackageInstantiation(PrimaryUnit, GenericInstantiationMixin): _packageReference: PackageReferenceSymbol _genericAssociations: List[GenericAssociationItem] - def __init__(self, identifier: str, uninstantiatedPackage: PackageReferenceSymbol, documentation: str = None): + def __init__(self, identifier: str, uninstantiatedPackage: PackageReferenceSymbol, documentation: Nullable[str] = None): super().__init__(identifier, documentation) GenericEntityInstantiationMixin.__init__(self) diff --git a/pyVHDLModel/Interface.py b/pyVHDLModel/Interface.py index fbbc4e3f9..015b185e3 100644 --- a/pyVHDLModel/Interface.py +++ b/pyVHDLModel/Interface.py @@ -34,7 +34,7 @@ Interface items are used in generic, port and parameter declarations. """ -from typing import Iterable +from typing import Iterable, Optional as Nullable from pyTooling.Decorators import export from pyTooling.MetaClasses import ExtendedType @@ -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) -> None: + def __init__(self, documentation: Nullable[str] = None) -> None: super().__init__(documentation) @@ -89,7 +89,7 @@ class ParameterInterfaceItemMixin(InterfaceItemMixin, mixin=True): @export class GenericConstantInterfaceItem(Constant, GenericInterfaceItemMixin, InterfaceItemWithModeMixin): - def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, defaultExpression, documentation) GenericInterfaceItemMixin.__init__(self) InterfaceItemWithModeMixin.__init__(self, mode) @@ -97,7 +97,7 @@ def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defa @export class GenericTypeInterfaceItem(Type, GenericInterfaceItemMixin): - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): super().__init__(identifier, documentation) GenericInterfaceItemMixin.__init__(self) @@ -109,35 +109,35 @@ class GenericSubprogramInterfaceItem(GenericInterfaceItemMixin): @export class GenericProcedureInterfaceItem(Procedure, GenericInterfaceItemMixin): - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): super().__init__(identifier, documentation) GenericInterfaceItemMixin.__init__(self) @export class GenericFunctionInterfaceItem(Function, GenericInterfaceItemMixin): - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): super().__init__(identifier, documentation) GenericInterfaceItemMixin.__init__(self) @export class GenericPackageInterfaceItem(GenericInterfaceItemMixin): - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): # super().__init__(identifier, documentation) GenericInterfaceItemMixin.__init__(self) @export class PortSignalInterfaceItem(Signal, PortInterfaceItemMixin): - def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, defaultExpression, documentation) PortInterfaceItemMixin.__init__(self, mode) @export class ParameterConstantInterfaceItem(Constant, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): - def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, defaultExpression, documentation) ParameterInterfaceItemMixin.__init__(self) InterfaceItemWithModeMixin.__init__(self, mode) @@ -145,7 +145,7 @@ def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defa @export class ParameterVariableInterfaceItem(Variable, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): - def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, defaultExpression, documentation) ParameterInterfaceItemMixin.__init__(self) InterfaceItemWithModeMixin.__init__(self, mode) @@ -153,7 +153,7 @@ def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defa @export class ParameterSignalInterfaceItem(Signal, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): - def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, defaultExpression, documentation) ParameterInterfaceItemMixin.__init__(self) InterfaceItemWithModeMixin.__init__(self, mode) @@ -161,6 +161,6 @@ def __init__(self, identifiers: Iterable[str], mode: Mode, subtype: Symbol, defa @export class ParameterFileInterfaceItem(File, ParameterInterfaceItemMixin): - def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, documentation) ParameterInterfaceItemMixin.__init__(self) diff --git a/pyVHDLModel/Name.py b/pyVHDLModel/Name.py index c4c282efd..920c009be 100644 --- a/pyVHDLModel/Name.py +++ b/pyVHDLModel/Name.py @@ -52,7 +52,7 @@ class Name(ModelEntity): _root: Nullable['Name'] # TODO: seams to be unused. There is no reverse linking, or? _prefix: Nullable['Name'] - def __init__(self, identifier: str, prefix: 'Name' = None): + def __init__(self, identifier: str, prefix: Nullable["Name"] = None): super().__init__() self._identifier = identifier diff --git a/pyVHDLModel/Namespace.py b/pyVHDLModel/Namespace.py index 5c2389ed7..d9c829d92 100644 --- a/pyVHDLModel/Namespace.py +++ b/pyVHDLModel/Namespace.py @@ -34,7 +34,7 @@ A helper class to implement namespaces and scopes. """ -from typing import TypeVar, Generic, Dict +from typing import TypeVar, Generic, Dict, Optional as Nullable from pyVHDLModel.Object import Obj, Signal, Constant, Variable @@ -51,7 +51,7 @@ class Namespace(Generic[K, O]): _subNamespaces: Dict[str, 'Namespace'] _elements: Dict[K, O] - def __init__(self, name: str, parentNamespace: 'Namespace' = None): + def __init__(self, name: str, parentNamespace: Nullable["Namespace"] = None): self._name = name self._parentNamespace = parentNamespace self._subNamespaces = {} diff --git a/pyVHDLModel/Object.py b/pyVHDLModel/Object.py index b1ab03c22..4b175f0e6 100644 --- a/pyVHDLModel/Object.py +++ b/pyVHDLModel/Object.py @@ -62,7 +62,7 @@ class Obj(ModelEntity, MultipleNamedEntityMixin, DocumentedEntityMixin): _subtype: Symbol _objectVertex: Nullable[Vertex] - def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: Nullable[str] = None): super().__init__() MultipleNamedEntityMixin.__init__(self, identifiers) DocumentedEntityMixin.__init__(self, documentation) @@ -92,7 +92,7 @@ class WithDefaultExpressionMixin(metaclass=ExtendedType, mixin=True): _defaultExpression: Nullable[ExpressionUnion] - def __init__(self, defaultExpression: ExpressionUnion = None) -> None: + def __init__(self, defaultExpression: Nullable[ExpressionUnion] = None) -> None: self._defaultExpression = defaultExpression if defaultExpression is not None: defaultExpression._parent = self @@ -123,7 +123,7 @@ class Constant(BaseConstant, WithDefaultExpressionMixin): constant BITS : positive := 8; """ - def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, documentation) WithDefaultExpressionMixin.__init__(self, defaultExpression) @@ -144,7 +144,7 @@ class DeferredConstant(BaseConstant): """ _constantReference: Nullable[Constant] - def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, documentation) @property @@ -169,7 +169,7 @@ class Variable(Obj, WithDefaultExpressionMixin): variable result : natural := 0; """ - def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, documentation) WithDefaultExpressionMixin.__init__(self, defaultExpression) @@ -198,7 +198,7 @@ class Signal(Obj, WithDefaultExpressionMixin): signal counter : unsigned(7 downto 0) := '0'; """ - def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: ExpressionUnion = None, documentation: str = None): + def __init__(self, identifiers: Iterable[str], subtype: Symbol, defaultExpression: Nullable[ExpressionUnion] = None, documentation: Nullable[str] = None): super().__init__(identifiers, subtype, documentation) WithDefaultExpressionMixin.__init__(self, defaultExpression) diff --git a/pyVHDLModel/Regions.py b/pyVHDLModel/Regions.py index b7751eb7f..00285fa6a 100644 --- a/pyVHDLModel/Regions.py +++ b/pyVHDLModel/Regions.py @@ -34,7 +34,7 @@ tbd. """ -from typing import List, Dict, Iterable +from typing import List, Dict, Iterable, Optional as Nullable from pyTooling.Decorators import export from pyTooling.MetaClasses import ExtendedType @@ -61,7 +61,7 @@ class ConcurrentDeclarationRegionMixin(metaclass=ExtendedType, mixin=True): _functions: Dict[str, Dict[str, Function]] _procedures: Dict[str, Dict[str, Procedure]] - def __init__(self, declaredItems: Iterable = None) -> None: + def __init__(self, declaredItems: Nullable[Iterable] = None) -> None: # TODO: extract to mixin self._declaredItems = [] # TODO: convert to dict if declaredItems is not None: diff --git a/pyVHDLModel/Sequential.py b/pyVHDLModel/Sequential.py index 91c9541af..d40ef7972 100644 --- a/pyVHDLModel/Sequential.py +++ b/pyVHDLModel/Sequential.py @@ -56,7 +56,7 @@ class SequentialStatement(Statement): class SequentialStatementsMixin(metaclass=ExtendedType, mixin=True): _statements: List[SequentialStatement] - def __init__(self, statements: Iterable[SequentialStatement] = None): + def __init__(self, statements: Nullable[Iterable[SequentialStatement]] = None): # TODO: extract to mixin self._statements = [] if statements is not None: @@ -71,14 +71,14 @@ def Statements(self) -> List[SequentialStatement]: @export class SequentialProcedureCall(SequentialStatement, ProcedureCallMixin): - def __init__(self, procedureName: Symbol, parameterMappings: Iterable[ParameterAssociationItem] = None, label: str = None): + def __init__(self, procedureName: Symbol, parameterMappings: Nullable[Iterable[ParameterAssociationItem]] = None, label: Nullable[str] = None): super().__init__(label) ProcedureCallMixin.__init__(self, procedureName, parameterMappings) @export class SequentialSignalAssignment(SequentialStatement, SignalAssignmentMixin): - def __init__(self, target: Symbol, label: str = None): + def __init__(self, target: Symbol, label: Nullable[str] = None): super().__init__(label) SignalAssignmentMixin.__init__(self, target) @@ -87,7 +87,7 @@ def __init__(self, target: Symbol, label: str = None): class SequentialSimpleSignalAssignment(SequentialSignalAssignment): _waveform: List[WaveformElement] - def __init__(self, target: Symbol, waveform: Iterable[WaveformElement], label: str = None): + def __init__(self, target: Symbol, waveform: Iterable[WaveformElement], label: Nullable[str] = None): super().__init__(target, label) # TODO: extract to mixin @@ -104,21 +104,21 @@ def Waveform(self) -> List[WaveformElement]: @export class SequentialVariableAssignment(SequentialStatement, VariableAssignmentMixin): - def __init__(self, target: Symbol, expression: ExpressionUnion, label: str = None): + def __init__(self, target: Symbol, expression: ExpressionUnion, label: Nullable[str] = None): super().__init__(label) VariableAssignmentMixin.__init__(self, target, expression) @export class SequentialReportStatement(SequentialStatement, ReportStatementMixin): - def __init__(self, message: ExpressionUnion, severity: ExpressionUnion = None, label: str = None): + def __init__(self, message: ExpressionUnion, severity: Nullable[ExpressionUnion] = None, label: Nullable[str] = None): super().__init__(label) ReportStatementMixin.__init__(self, message, severity) @export class SequentialAssertStatement(SequentialStatement, AssertStatementMixin): - def __init__(self, condition: ExpressionUnion, message: ExpressionUnion = None, severity: ExpressionUnion = None, label: str = None): + def __init__(self, condition: ExpressionUnion, message: Nullable[ExpressionUnion] = None, severity: Nullable[ExpressionUnion] = None, label: Nullable[str] = None): super().__init__(label) AssertStatementMixin.__init__(self, condition, message, severity) @@ -132,28 +132,28 @@ class CompoundStatement(SequentialStatement): class Branch(ModelEntity, SequentialStatementsMixin): """A ``Branch`` is a base-class for all branches in a if statement.""" - def __init__(self, statements: Iterable[SequentialStatement] = None): + def __init__(self, statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__() SequentialStatementsMixin.__init__(self, statements) @export class IfBranch(Branch, IfBranchMixin): - def __init__(self, condition: ExpressionUnion, statements: Iterable[SequentialStatement] = None): + def __init__(self, condition: ExpressionUnion, statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__(statements) IfBranchMixin.__init__(self, condition) @export class ElsifBranch(Branch, ElsifBranchMixin): - def __init__(self, condition: ExpressionUnion, statements: Iterable[SequentialStatement] = None): + def __init__(self, condition: ExpressionUnion, statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__(statements) ElsifBranchMixin.__init__(self, condition) @export class ElseBranch(Branch, ElseBranchMixin): - def __init__(self, statements: Iterable[SequentialStatement] = None): + def __init__(self, statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__(statements) ElseBranchMixin.__init__(self) @@ -164,7 +164,7 @@ class IfStatement(CompoundStatement): _elsifBranches: List['ElsifBranch'] _elseBranch: Nullable[ElseBranch] - def __init__(self, ifBranch: IfBranch, elsifBranches: Iterable[ElsifBranch] = None, elseBranch: ElseBranch = None, label: str = None): + def __init__(self, ifBranch: IfBranch, elsifBranches: Nullable[Iterable[ElsifBranch]] = None, elseBranch: Nullable[ElseBranch] = None, label: Nullable[str] = None): super().__init__(label) self._ifBranch = ifBranch @@ -240,7 +240,7 @@ def __str__(self) -> str: class SequentialCase(BaseCase, SequentialStatementsMixin): _choices: List - def __init__(self, statements: Iterable[SequentialStatement] = None): + def __init__(self, statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__() SequentialStatementsMixin.__init__(self, statements) @@ -253,7 +253,7 @@ def Choices(self) -> List[BaseChoice]: @export class Case(SequentialCase): - def __init__(self, choices: Iterable[SequentialChoice], statements: Iterable[SequentialStatement] = None): + def __init__(self, choices: Iterable[SequentialChoice], statements: Nullable[Iterable[SequentialStatement]] = None): super().__init__(statements) self._choices = [] @@ -281,7 +281,7 @@ class CaseStatement(CompoundStatement): _expression: ExpressionUnion _cases: List[SequentialCase] - def __init__(self, expression: ExpressionUnion, cases: Iterable[SequentialCase], label: str = None): + def __init__(self, expression: ExpressionUnion, cases: Iterable[SequentialCase], label: Nullable[str] = None): super().__init__(label) self._expression = expression @@ -306,7 +306,7 @@ def Cases(self) -> List[SequentialCase]: class LoopStatement(CompoundStatement, SequentialStatementsMixin): """A ``LoopStatement`` is a base-class for all loop statements.""" - def __init__(self, statements: Iterable[SequentialStatement] = None, label: str = None): + def __init__(self, statements: Nullable[Iterable[SequentialStatement]] = None, label: Nullable[str] = None): super().__init__(label) SequentialStatementsMixin.__init__(self, statements) @@ -321,7 +321,7 @@ class ForLoopStatement(LoopStatement): _loopIndex: str _range: Range - def __init__(self, loopIndex: str, rng: Range, statements: Iterable[SequentialStatement] = None, label: str = None): + def __init__(self, loopIndex: str, rng: Range, statements: Nullable[Iterable[SequentialStatement]] = None, label: Nullable[str] = None): super().__init__(statements, label) self._loopIndex = loopIndex @@ -340,7 +340,7 @@ def Range(self) -> Range: @export class WhileLoopStatement(LoopStatement, ConditionalMixin): - def __init__(self, condition: ExpressionUnion, statements: Iterable[SequentialStatement] = None, label: str = None): + def __init__(self, condition: ExpressionUnion, statements: Nullable[Iterable[SequentialStatement]] = None, label: Nullable[str] = None): super().__init__(statements, label) ConditionalMixin.__init__(self, condition) @@ -351,7 +351,7 @@ class LoopControlStatement(SequentialStatement, ConditionalMixin): _loopReference: LoopStatement - def __init__(self, condition: ExpressionUnion = None, loopLabel: str = None) -> None: # TODO: is this label (currently str) a Name or a Label class? + def __init__(self, condition: Nullable[ExpressionUnion] = None, loopLabel: Nullable[str] = None) -> None: # TODO: is this label (currently str) a Name or a Label class? super().__init__() ConditionalMixin.__init__(self, condition) @@ -382,7 +382,7 @@ class NullStatement(SequentialStatement): class ReturnStatement(SequentialStatement, ConditionalMixin): _returnValue: ExpressionUnion - def __init__(self, returnValue: ExpressionUnion = None) -> None: + def __init__(self, returnValue: Nullable[ExpressionUnion] = None) -> None: super().__init__() ConditionalMixin.__init__(self, returnValue) @@ -398,7 +398,7 @@ class WaitStatement(SequentialStatement, ConditionalMixin): _sensitivityList: Nullable[List[Symbol]] _timeout: ExpressionUnion - def __init__(self, sensitivityList: Iterable[Symbol] = None, condition: ExpressionUnion = None, timeout: ExpressionUnion = None, label: str = None): + def __init__(self, sensitivityList: Nullable[Iterable[Symbol]] = None, condition: Nullable[ExpressionUnion] = None, timeout: Nullable[ExpressionUnion] = None, label: Nullable[str] = None): super().__init__(label) ConditionalMixin.__init__(self, condition) diff --git a/pyVHDLModel/Subprogram.py b/pyVHDLModel/Subprogram.py index be4361cf3..0a3cd0836 100644 --- a/pyVHDLModel/Subprogram.py +++ b/pyVHDLModel/Subprogram.py @@ -34,7 +34,7 @@ Subprograms are procedures, functions and methods. """ -from typing import List +from typing import List, Optional as Nullable from pyTooling.Decorators import export from pyTooling.MetaClasses import ExtendedType @@ -52,7 +52,7 @@ class Subprogram(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): _statements: List['SequentialStatement'] _isPure: bool - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): super().__init__() NamedEntityMixin.__init__(self, identifier) DocumentedEntityMixin.__init__(self, documentation) @@ -85,7 +85,7 @@ def IsPure(self) -> bool: @export class Procedure(Subprogram): - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): super().__init__(identifier, documentation) self._isPure = False @@ -94,7 +94,7 @@ def __init__(self, identifier: str, documentation: str = None): class Function(Subprogram): _returnType: Subtype - def __init__(self, identifier: str, isPure: bool = True, documentation: str = None): + def __init__(self, identifier: str, isPure: bool = True, documentation: Nullable[str] = None): super().__init__(identifier, documentation) self._isPure = isPure diff --git a/pyVHDLModel/Type.py b/pyVHDLModel/Type.py index c331990a7..8493a7c10 100644 --- a/pyVHDLModel/Type.py +++ b/pyVHDLModel/Type.py @@ -34,7 +34,7 @@ Types. """ -from typing import Union, List, Iterator, Iterable, Tuple +from typing import Union, List, Iterator, Iterable, Tuple, Optional as Nullable from pyTooling.Decorators import export from pyTooling.MetaClasses import ExtendedType @@ -52,7 +52,7 @@ class BaseType(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): _objectVertex: Vertex - def __init__(self, identifier: str, documentation: str = None): + def __init__(self, identifier: str, documentation: Nullable[str] = None): """ Initializes underlying ``BaseType``. @@ -275,7 +275,7 @@ def __str__(self) -> str: class RecordType(CompositeType): _elements: List[RecordTypeElement] - def __init__(self, identifier: str, elements: Iterable[RecordTypeElement] = None): + def __init__(self, identifier: str, elements: Nullable[Iterable[RecordTypeElement]] = None): super().__init__(identifier) self._elements = [] # TODO: convert to dict diff --git a/pyVHDLModel/__init__.py b/pyVHDLModel/__init__.py index b5447c416..007f61955 100644 --- a/pyVHDLModel/__init__.py +++ b/pyVHDLModel/__init__.py @@ -427,7 +427,7 @@ class Design(ModelEntity): _objectGraph: Graph[None, None, None, None, None, None, None, None, str, Obj, None, None, None, None, None, None, None, None, None, None, None, None, None] #: The graph of all types and objects in the design. _toplevel: Union[Entity, Configuration] #: When computed, the toplevel design unit is cached in this field. - def __init__(self, name: str = None) -> None: + def __init__(self, name: Nullable[str] = None) -> None: """ Initializes a VHDL design. @@ -1470,7 +1470,7 @@ class Document(ModelEntity, DocumentedEntityMixin): _dependencyVertex: Vertex[None, None, None, 'Document', None, None, None, None, None, None, None, None, None, None, None, None, None] _compileOrderVertex: Vertex[None, None, None, 'Document', None, None, None, None, None, None, None, None, None, None, None, None, None] - def __init__(self, path: Path, documentation: str = None): + def __init__(self, path: Path, documentation: Nullable[str] = None): super().__init__() DocumentedEntityMixin.__init__(self, documentation) diff --git a/pyproject.toml b/pyproject.toml index 3ffa809fa..6eb716cc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ - "setuptools ~= 69.5", - "wheel ~= 0.40.0", + "setuptools ~= 70.0", + "wheel ~= 0.43", "pyTooling ~= 6.3" ] build-backend = "setuptools.build_meta" @@ -45,9 +45,6 @@ relative_files = true omit = [ "*site-packages*", "setup.py", - "tests/benchmark/*", - "tests/performance/*", - "tests/platform/*", "tests/unit/*" ]