Commit aae71b64 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Addressed all pylint reports.

parent b25adcd1
......@@ -24,7 +24,7 @@ code generator A.'''
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List
from ..commonPy.utility import panic
......
......@@ -24,7 +24,7 @@ code generator A.'''
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List
from ..commonPy.utility import panic
......
......@@ -247,7 +247,7 @@ def OnShutdown(unused_badTypes: SetOfBadTypenames) -> None:
pass
class Params(object):
class Params:
cTypes = {
"BOOLEAN": "flag",
"INTEGER": "asn1SccSint",
......@@ -302,8 +302,8 @@ def CommonBaseImpl(comment: str,
path: str,
params: Params,
accessPathInC: str,
postfix: str="",
returnPointer: bool=False) -> None:
postfix: str = "",
returnPointer: bool = False) -> None:
takeAddr = '&' if returnPointer else ''
g_outputGetSetH.write("\n/* %s */\n%s %s_Get%s(%s);\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("\n/* %s */\n%s %s_Get%s(%s)\n" % (comment, ctype, path, postfix, params.GetDecl()))
......@@ -324,7 +324,7 @@ def CommonBaseImplSequenceFixed(comment: str,
params: Params,
_: str,
node: Union[AsnSequenceOf, AsnSetOf, AsnString],
postfix: str="") -> None:
postfix: str = "") -> None:
g_outputGetSetH.write("\n/* %s */\n%s %s_Get%s(%s);\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("\n/* %s */\n%s %s_Get%s(%s)\n" % (comment, ctype, path, postfix, params.GetDecl()))
g_outputGetSetC.write("{\n")
......@@ -568,7 +568,7 @@ def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict:
panic("Unexpected ASN.1 type... Send this grammar to ESA") # pragma: no cover
def CreateDeclarationsForAllTypes(names: AST_Lookup, leafTypeDict: AST_Leaftypes, badTypes: SetOfBadTypenames) -> None:
def CreateDeclarationsForAllTypes(names: AST_Lookup, leafTypeDict: AST_Leaftypes, unused_badTypes: SetOfBadTypenames) -> None:
for nodeTypename in names:
# Do not ignore the so called "bad types". In python, IA5Strings are supported
if not names[nodeTypename]._isArtificial: # and nodeTypename not in badTypes:
......
......@@ -29,7 +29,7 @@ import os
import sys
import re
import distutils.spawn as spawn
from distutils import spawn
from typing import List, Union, Set # NOQA
from ..commonPy import asnParser
......
......@@ -88,7 +88,7 @@ def FixupNestedStringsAndEnumerated() -> None:
node = names[nodeTypename]
if isinstance(node, (AsnSequence, AsnChoice, AsnSet)):
for child in node._members:
if isinstance(child[1], AsnString) or isinstance(child[1], AsnEnumerated):
if isinstance(child[1], (AsnString, AsnEnumerated)):
newName = nodeTypename + "_" + child[0] # pragma: no cover
while newName in names: # pragma: no cover
newName += "_t" # pragma: no cover
......@@ -158,7 +158,7 @@ def RenderElements(controlString: str) -> None:
else:
# This is a bug in pylint - scheduled to be fixed in next release, by:
# https://github.com/PyCQA/pylint/commit/6d31776454b5e308e4b869a1893b39083dca3146
newElement = g_doc.createElement(finalElementName) # pylint: disable=redefined-variable-type
newElement = g_doc.createElement(finalElementName)
if attributes:
for atr in attributes:
# This is a bug in pylint - scheduled to be fixed in next release, by:
......@@ -168,7 +168,7 @@ def RenderElements(controlString: str) -> None:
parent = createdElements[under]
parent.appendChild(newElement)
createdElements[finalElementName] = newElement
parent = newElement # pylint: disable=redefined-variable-type
parent = newElement
def GetOID(nodeTypename: str) -> str:
......@@ -259,7 +259,7 @@ def OnBasic(nodeTypename: str, node: AsnBasicNode, unused_leafTypeDict: AST_Leaf
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnSequence, AsnSet, AsnChoice],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
if nodeTypename in g_declaredTypes:
return
g_declaredTypes.add(nodeTypename)
......
......@@ -209,7 +209,7 @@ def CreateDeclarationForType(nodeTypename: str, names: AST_Lookup, leafTypeDict:
CreateAlias(nodeTypename, "int32", "values of ENUMERATED %s" % nodeTypename)
g_outputFile.write("\n")
elif isinstance(node, (AsnSequence, AsnSet, AsnChoice)):
if len(node._members) == 0:
if not node._members:
panic("Simulink_A_mapper: Simulink can't support empty Seq/Set/Choice! (%s)" % node.Location()) # pragma: no cover
elemNo = 0
if isinstance(node, AsnChoice):
......
......@@ -46,7 +46,7 @@ def Version() -> None:
# noinspection PyDefaultArgument
def getUID(strIdentifier: str, idStore: Dict[str, str]={}) -> str: # pylint: disable=dangerous-default-value
def getUID(strIdentifier: str, idStore: Dict[str, str] = {}) -> str: # pylint: disable=dangerous-default-value
def h(digits: int) -> str:
ret = ""
for _ in range(0, digits):
......
......@@ -211,7 +211,7 @@ CREATE TABLE {cleanTypename} (
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnChoice, AsnSet, AsnSequence],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
cleanTypename = CleanName(nodeTypename)
g_sqlOutput.write(
'\nCREATE TABLE {cleanTypename} (\n id int NOT NULL,\n'.format(
......
......@@ -252,7 +252,7 @@ class {cleanTypename}_SQL(Base):
def CommonSeqSetChoice(nodeTypename: str,
node: Union[AsnSet, AsnSequence, AsnChoice],
unused_leafTypeDict: AST_Leaftypes,
isChoice: bool=False) -> None:
isChoice: bool = False) -> None:
cleanTypename = CleanName(nodeTypename)
choiceField = ''
if isChoice:
......
......@@ -9,7 +9,7 @@ file created by Maxime Perrotin.
import os
import sys
import distutils.spawn as spawn
from distutils import spawn
from typing import List, Union
from ..commonPy.utility import panic
......
......@@ -519,7 +519,7 @@ def WriteCodeForGUIControls(
varPrefix = prefix.replace("::", "_")
txtPrefix = re.sub(r'^.*::', '', prefix)
# Depending on the type of the node, create the appropriate controls
if isinstance(node, AsnInt) or isinstance(node, AsnReal) or isinstance(node, AsnOctetString):
if isinstance(node, (AsnInt, AsnReal, AsnOctetString)):
# Write a static label before the child
g_MyCreation.write("wxStaticText* itemStaticText_%s = new wxStaticText( %s, wxID_STATIC, _(\"%s\"), wxDefaultPosition, wxDefaultSize, 0 );\n" %
(varPrefix, ScrollWnd, txtPrefix))
......@@ -655,7 +655,7 @@ def maybeElseZero(childNo: int) -> str:
def CopyDataFromDlgToASN1(f: IO[Any], srcVar: str, destVar: str, node: AsnNode, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> None:
if isinstance(node, AsnInt) or isinstance(node, AsnReal):
if isinstance(node, (AsnInt, AsnReal)):
targetType = {"INTEGER": "asn1SccSint", "REAL": "double"}[node._leafType]
f.write("if (false == StringToAny<%s>(\"%s\", _itemTextCtrl_%s->GetValue().ToAscii().release(), %s, msgError)) {\n" % (targetType, srcVar, srcVar, destVar))
f.write(" wxMessageBox(wxConvLocal.cMB2WC(msgError.c_str()), _T(\"Data input error\"), wxICON_ERROR);\n")
......@@ -727,7 +727,7 @@ def CopyDataFromASN1ToDlg(fDesc: IO[Any],
node: AsnNode,
leafTypeDict: AST_Leaftypes,
names: AST_Lookup,
bClear: bool=False) -> None:
bClear: bool = False) -> None:
if isinstance(node, AsnInt):
fDesc.write("{\n")
fDesc.write(" ostringstream s;\n")
......@@ -896,7 +896,7 @@ def WriteCodeForGnuPlot(prefix: str, node: AsnNode, subProgram: ApLevelContainer
CleanParam = CleanName(param._id)
if prefix in ("TCDATA: ", "TMDATA: "):
prefix += CleanSP + "::" + CleanParam
if isinstance(node, AsnInt) or isinstance(node, AsnReal) or isinstance(node, AsnOctetString):
if isinstance(node, (AsnInt, AsnReal, AsnOctetString)):
g_GnuplotFile.write(prefix + '\n')
elif isinstance(node, AsnBool):
pass
......@@ -988,7 +988,7 @@ def Common(nodeTypename: str,
control = "itemBoxSizer_%s" % CleanName(subProgram._id)
WriteCodeForGUIControls('', control, node, subProgram, subProgramImplementation, param, leafTypeDict, names)
global g_bBraceOpen
if len(g_SPs) == 0 or subProgram._id != g_SPs[-1]:
if not g_SPs or subProgram._id != g_SPs[-1]:
if g_bBraceOpen:
g_MyAction.write("} // %s\n" % g_SPs[-1])
g_MySave.write("} // %s\n" % g_SPs[-1])
......
......@@ -168,6 +168,7 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in);
# pylint: disable=unused-argument
# pylint: disable=no-self-use
class MapUPyObjData(RecursiveMapperGeneric[str, str]):
def __init__(self) -> None:
pass
......@@ -265,7 +266,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
def MapInteger(self, srcVar: str, destVar: Tuple[str, str], _: AsnInt, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
# TODO check range of integer
dest, _ = destVar
dest, unused = destVar
return ['%s = mp_obj_new_int(%s);' % (dest, srcVar)]
def MapReal(self, srcVar: str, destVar: Tuple[str, str], _: AsnReal, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
......@@ -279,7 +280,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
]
def MapBoolean(self, srcVar: str, destVar: Tuple[str, str], _: AsnBool, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
dest, _ = destVar
dest, unused = destVar
return ['%s = mp_obj_new_bool(%s);' % (dest, srcVar)]
def MapOctetString(self, srcVar: str, destVar: Tuple[str, str], node: AsnOctetString, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
......@@ -299,7 +300,7 @@ class MapUPyObjEncode(RecursiveMapperGeneric[str, Tuple[str, str]]):
def MapEnumerated(self, srcVar: str, destVar: Tuple[str, str], _: AsnEnumerated, __: AST_Leaftypes, ___: AST_Lookup) -> List[str]:
# TODO check the enum value fits in a small int and use MP_OBJ_NEW_SMALL_INT
dest, _ = destVar
dest, unused = destVar
return ['%s = mp_obj_new_int(%s);' % (dest, srcVar)]
def MapSequence(self, srcVar: str, destVar: Tuple[str, str], node: AsnSequenceOrSet, leafTypeDict: AST_Leaftypes, names: AST_Lookup) -> List[str]:
......
......@@ -687,7 +687,7 @@ class OG_GlueGenerator(ASynchronousToolGlueGenerator):
fileOutHeader.write("}\n\n")
coding = {"uper": "UPER", "native": "NATIVE", "acn": "ACN"}[encoding.lower()]
if isinstance(node, AsnInt) or isinstance(node, AsnBool) or isinstance(node, AsnReal) or isinstance(node, AsnEnumerated):
if isinstance(node, (AsnInt, AsnBool, AsnReal, AsnEnumerated)):
fileOutHeader.write(
"#define ENCODE_SYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, param1)\n\n" %
(coding,
......
......@@ -574,7 +574,7 @@ def WriteCodeForGUIControls(prefixes: List[str], # pylint: disable=invalid-sequ
if len(parentControl) >= i:
pyStr += "[{index}]".format(index=parentControl[i - 1])
for item in prefixes[i][len(prefixes[i - 1]):].split('.'):
if len(item) > 0:
if item:
pyStr += '''["{prefixKey}"]'''.format(prefixKey=item)
if isinstance(node, (AsnInt, AsnReal, AsnOctetString)):
......
......@@ -57,7 +57,7 @@ def IsElementMappedToPrimitive(node: AsnSequenceOrSetOf, names: AST_Lookup) -> b
contained = node._containedType
while isinstance(contained, str):
contained = names[contained]
return isinstance(contained, AsnInt) or isinstance(contained, AsnReal) or isinstance(contained, AsnBool) or isinstance(contained, AsnEnumerated)
return isinstance(contained, (AsnInt, AsnReal, AsnBool, AsnEnumerated))
# pylint: disable=no-self-use
......
......@@ -489,7 +489,7 @@ class RTDS_GlueGenerator(ASynchronousToolGlueGenerator):
fileOutHeader = self.C_HeaderFile
fileOutSource = self.C_SourceFile
isPointer = True
if isinstance(node, AsnBasicNode) or isinstance(node, AsnEnumerated):
if isinstance(node, (AsnBasicNode, AsnEnumerated)):
isPointer = False
cleaned = self.CleanNameAsToolWants(nodeTypename)
fileOutHeader.write(
......
......@@ -688,7 +688,7 @@ class OG_GlueGenerator(ASynchronousToolGlueGenerator):
fileOutHeader.write("}\n\n")
coding = {"uper": "UPER", "native": "NATIVE", "acn": "ACN"}[encoding.lower()]
if isinstance(node, AsnInt) or isinstance(node, AsnBool) or isinstance(node, AsnReal) or isinstance(node, AsnEnumerated):
if isinstance(node, (AsnInt, AsnBool, AsnReal, AsnEnumerated)):
fileOutHeader.write(
"#define ENCODE_SYNC_%s_%s(varName, param1) ENCODE_%s_%s(varName, param1)\n\n" %
(coding,
......
......@@ -55,7 +55,7 @@ def IsElementMappedToPrimitive(node: AsnSequenceOrSetOf, names: AST_Lookup) -> b
contained = node._containedType
while isinstance(contained, str):
contained = names[contained]
return isinstance(contained, AsnInt) or isinstance(contained, AsnReal) or isinstance(contained, AsnBool) or isinstance(contained, AsnEnumerated)
return isinstance(contained, (AsnInt, AsnReal, AsnBool, AsnEnumerated))
# pylint: disable=no-self-use
......
......@@ -1187,7 +1187,7 @@ def OnFinal() -> None:
systemcBody.write(' }\n')
systemcBody.write('}\n\n')
AddToStr('outputs', ', '.join(outputs) + (', ' if len(outputs) else ''))
AddToStr('outputs', ', '.join(outputs) + (', ' if outputs else ''))
AddToStr('completions', ', '.join(completions))
from . import vhdlTemplate
......
......@@ -33,6 +33,8 @@ parameters, which have C callable interfaces. The necessary
stubs (to allow calling from the VM side) are also generated.
'''
# pylint: disable=too-many-lines
import os
import re
import math
......@@ -122,7 +124,7 @@ class VHDL_Circuit:
allCircuits = [] # type: List[VHDL_Circuit]
lookupSP = {} # type: Dict[str, VHDL_Circuit]
currentCircuit = None # type: VHDL_Circuit
names = None # type: asnParser.AST_Lookup
names = {} # type: asnParser.AST_Lookup
leafTypeDict = None # type: asnParser.AST_Leaftypes
currentOffset = 0x0 # type: int
......@@ -1210,11 +1212,11 @@ def OnFinal() -> None:
# systemcBody.write(' }\n')
# systemcBody.write('}\n\n')
AddToStr('outputs', ', '.join(outputs) + (', ' if len(outputs) else ''))
AddToStr('outputs', ', '.join(outputs) + (', ' if outputs else ''))
AddToStr('completions', ', '.join(completions))
# Handle invalid write accesses in the passinput space by kicking off the last circuit (i.e. an FDIR circuit)
if len(VHDL_Circuit.allCircuits) > 0:
if VHDL_Circuit.allCircuits:
alternate_kickoffWriteAccess = "when others => %(pi)s_StartCalculationsInternal <= %(pi)s_StartCalculationsInternal xor '1';\n" % {'pi': VHDL_Circuit.allCircuits[-1]._spCleanName}
AddToStr('readinputdata', ' ' * 22 + alternate_kickoffWriteAccess)
......
......@@ -84,7 +84,7 @@ AsnSequenceOrSet = Union['AsnSequence', 'AsnSet']
AsnSequenceOrSetOf = Union['AsnSequenceOf', 'AsnSetOf']
class AsnNode(object):
class AsnNode:
def __init__(self, asnFilename: str) -> None:
self._leafType = "unknown"
......@@ -95,7 +95,7 @@ class AsnNode(object):
def Location(self) -> str:
return "file %s, line %d" % (self._asnFilename, int(self._lineno)) # pragma: no cover
def IdenticalPerSMP2(self, other: 'AsnNode', mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, unused_other: 'AsnNode', unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
utility.panic("internal error: Must be defined in derived class...")
def AsASN1(self, _: Lookup) -> str: # pylint: disable=no-self-use
......@@ -154,7 +154,7 @@ Members:
result += ", default value " + self._bDefaultValue # pragma: no cover
return result
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, other: AsnNode, unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
return isinstance(other, AsnBool)
def AsASN1(self, _: Lookup) -> str:
......@@ -189,7 +189,7 @@ Members:
result += " with default value of %s" % self._iDefaultValue # pragma: no cover
return result
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, other: AsnNode, unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
return isinstance(other, AsnInt) and CommonIdenticalRangePerSMP2(self._range, other._range)
def AsASN1(self, _: Lookup) -> str:
......@@ -246,7 +246,7 @@ Members:
result += " within [%s,%s]" % (self._range[0], self._range[1])
return result
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, other: AsnNode, unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
return isinstance(other, AsnReal) and CommonIdenticalRangePerSMP2(self._range, other._range)
def AsASN1(self, _: Lookup) -> str:
......@@ -284,7 +284,7 @@ Members:
result += str(self._range)
return result
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, other: AsnNode, unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
return isinstance(other, AsnString) and CommonIdenticalRangePerSMP2(self._range, other._range)
def AsASN1(self, _: Lookup) -> str:
......@@ -407,7 +407,7 @@ Members:
result += str(member)
return result
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool: # pylint: disable=no-self-use
def IdenticalPerSMP2(self, other: AsnNode, unused_mynames: Lookup, unused_othernames: Lookup) -> bool: # pylint: disable=no-self-use
return isinstance(other, AsnEnumerated) and sorted(self._members) == sorted(other._members)
def AsASN1(self, _: Lookup) -> str:
......
......@@ -45,6 +45,9 @@ ASN.1 Parser
This module parses ASN.1 grammars and creates an abstract syntax tree (AST)
inside configMT.inputCodeAST, for use with the code generators.
'''
# pylint: disable=too-many-lines
import os
import sys
import copy
......@@ -384,7 +387,7 @@ def CheckForInvalidKeywords(node_or_str: Union[str, AsnNode]) -> None:
def ParseAsnFileList(listOfFilenames: List[str]) -> None: # pylint: disable=invalid-sequence-index
# Add basic ASN.1 caching to avoid calling the ASN.1 compiler over and over
projectCache = os.getenv ("PROJECT_CACHE")
projectCache = os.getenv("PROJECT_CACHE")
if projectCache is not None and not os.path.isdir(projectCache):
utility.panic(
"The configured cache folder:\n\n\t" + projectCache + "\n\n...is not there!\n")
......
......@@ -61,8 +61,8 @@ def ScanChildren(
node: AsnNode,
names: Dict[str, AsnNode],
results: List[str], # pylint: disable=invalid-sequence-index
isRoot: bool=False,
createInnerNodesInNames: bool=True) -> None:
isRoot: bool = False,
createInnerNodesInNames: bool = True) -> None:
'''
Find all the types that this one (nodeTypename, node) depends on.
and return them in the 'results' list. Use 'names' to lookup
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment