Commit b25adcd1 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Addressing pylint reports.

parent a6ec5483
......@@ -165,6 +165,8 @@ 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:
......@@ -263,7 +265,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, data = destVar
dest, _ = 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]:
......@@ -277,7 +279,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, data = destVar
dest, _ = 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]:
......@@ -297,7 +299,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, data = destVar
dest, _ = 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]:
......@@ -490,9 +492,9 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
try:
return self.neededQstrFields[fields][0]
except KeyError:
id = 'upython_qstr_fields%u' % len(self.neededQstrFields)
self.neededQstrFields[fields] = (id, fields)
return id
ide = 'upython_qstr_fields%u' % len(self.neededQstrFields)
self.neededQstrFields[fields] = (ide, fields)
return ide
def AddChoiceFields(self, choiceNode: AsnChoice, fields: List[str]) -> None:
self.choiceNodes[choiceNode] = fields
......@@ -614,8 +616,8 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
# Generate the init function
lines = []
for id, fields in self.neededQstrFields.values():
lines.append('qstr %s[%u];' % (id, len(fields)))
for ide, fields in self.neededQstrFields.values():
lines.append('qstr %s[%u];' % (ide, len(fields)))
lines.append('')
lines.append('void mp_taste_types_init(void) {')
lines.append(' static int inited = 0;')
......@@ -623,9 +625,9 @@ class MicroPython_GlueGenerator(ASynchronousToolGlueGenerator):
lines.append(' return;')
lines.append(' }')
lines.append(' inited = 1;')
for id, fields in self.neededQstrFields.values():
for ide, fields in self.neededQstrFields.values():
for i, f in enumerate(fields):
lines.append(' %s[%u] = qstr_from_str("%s");' % (id, i, f))
lines.append(' %s[%u] = qstr_from_str("%s");' % (ide, i, f))
lines.append('}')
self.C_SourceFile.write('\n'.join(lines) + '\n\n')
......
......@@ -546,7 +546,7 @@ def WriteCodeForGUIControls(prefixes: List[str], # pylint: disable=invalid-sequ
param: Param,
leafTypeDict: AST_Leaftypes,
names: AST_Lookup,
nodeTypename: str='') -> None:
nodeTypename: str = '') -> None:
global g_firstElem
global g_onceOnly
global g_asnId
......@@ -627,7 +627,7 @@ def WriteCodeForGUIControls(prefixes: List[str], # pylint: disable=invalid-sequ
nodeTypename, node._name, txtPrefix))
if isinstance(node, AsnChoice):
g_PyDataModel.write('''"choices":[''')
elif isinstance(node, AsnSequence) or isinstance(node, AsnSet):
elif isinstance(node, (AsnSequence, AsnSet)):
g_PyDataModel.write('''"children":[''')
# Recurse on children
if node._members:
......
......@@ -127,7 +127,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
......@@ -1042,7 +1042,7 @@ def OnFinal() -> None:
totalIn = 0
for p in VHDL_Circuit.allCircuits[0]._sp._params:
if isinstance(p, InParam) or isinstance(p, InOutParam):
if isinstance(p, (InParam, InOutParam)):
totalIn += RegistersAllocated(p._signal._asnNodename)
AddToStr('numberOfInputRegisters', str(totalIn / 4))
......
......@@ -499,7 +499,7 @@ Members:
isinstance(other, (AsnSet, AsnSequence, AsnChoice)) and \
CommonIdenticalCheck(self, other, mynames, othernames)
def AsASN1(self, typeDict: Lookup=None) -> str:
def AsASN1(self, typeDict: Lookup = None) -> str:
if typeDict is None:
typeDict = {}
return CommonAsASN1('SEQUENCE', self, typeDict)
......@@ -540,7 +540,7 @@ class AsnSet(AsnComplexNode):
isinstance(other, (AsnSet, AsnSequence, AsnChoice)) and \
CommonIdenticalCheck(self, other, mynames, othernames)
def AsASN1(self, typeDict: Lookup=None) -> str:
def AsASN1(self, typeDict: Lookup = None) -> str:
if typeDict is None:
typeDict = {}
return CommonAsASN1('SET', self, typeDict)
......@@ -586,7 +586,7 @@ Members:
def IdenticalPerSMP2(self, other: AsnNode, mynames: Lookup, othernames: Lookup) -> bool:
return isinstance(other, AsnChoice) and CommonIdenticalCheck(self, other, mynames, othernames)
def AsASN1(self, typeDict: Lookup=None) -> str:
def AsASN1(self, typeDict: Lookup = None) -> str:
if typeDict is None:
typeDict = {}
return CommonAsASN1('CHOICE', self, typeDict)
......@@ -660,7 +660,7 @@ Members:
isinstance(other, (AsnSequenceOf, AsnSetOf)) and \
CommonIdenticalArrayCheck(self, other, mynames, othernames)
def AsASN1(self, typeDict: Lookup=None) -> str:
def AsASN1(self, typeDict: Lookup = None) -> str:
if typeDict is None:
typeDict = {}
return CommonAsASN1array('SEQUENCE', self, typeDict)
......@@ -693,7 +693,7 @@ class AsnSetOf(AsnComplexNode):
isinstance(other, (AsnSequenceOf, AsnSetOf)) and \
CommonIdenticalArrayCheck(self, other, mynames, othernames)
def AsASN1(self, typeDict: Lookup=None) -> str:
def AsASN1(self, typeDict: Lookup = None) -> str:
if typeDict is None:
typeDict = {}
return CommonAsASN1array('SET', self, typeDict)
......
......@@ -50,7 +50,7 @@ import sys
import copy
import tempfile
import re
import distutils.spawn as spawn
from distutils import spawn
import hashlib
import xml.sax # type: ignore
......@@ -236,7 +236,7 @@ def VerifyAndFixAST() -> Dict[str, str]:
if lastEquivalents == equivalents and lastKnownTypes == knownTypes and lastUnknownTypes == unknownTypes:
break
if len(unknownTypes) != 0:
if unknownTypes:
utility.panic('AsnParser: Types remain unknown after symbol fixup:\n%s\n' % list(unknownTypes.keys()))
# Remove all AsnMetaTypes from the ast
......@@ -401,7 +401,7 @@ def ParseAsnFileList(listOfFilenames: List[str]) -> None: # pylint: disable=inv
filehash.update(each.encode('utf-8'))
newHash = filehash.hexdigest()
# set the name of the XML files containing the dumped ASTs
xmlAST = projectCache + os.sep + newHash + "_ast_v4.xml"
xmlAST = projectCache + os.sep + newHash + "_ast_v4.xml"
xmlAST2 = projectCache + os.sep + newHash + "_ast_v1.xml"
if not os.path.exists(xmlAST) or not os.path.exists(xmlAST2):
someFilesHaveChanged = True
......@@ -499,7 +499,7 @@ class Element:
class InputFormatXMLHandler(xml.sax.ContentHandler): # type: ignore
def __init__(self, debug: bool=False) -> None:
def __init__(self, debug: bool = False) -> None:
xml.sax.ContentHandler.__init__(self) # type: ignore
self._debug = False
if debug:
......@@ -695,7 +695,7 @@ def CommonSetSeqOf(newModule: Module, lineNo: int, xmlSequenceOfNode: Element, c
if xmlType is None:
utility.panic("CommonSetSeqOf: No child under SequenceOfType (%s, %s)" % # pragma: no cover
(newModule._asnFilename, lineNo)) # pragma: no cover
if len(xmlType._children) == 0:
if len(xmlType._children) == 0: # pylint: disable=len-as-condition
utility.panic("CommonSetSeqOf: No children for Type (%s, %s)" % # pragma: no cover
(newModule._asnFilename, lineNo)) # pragma: no cover
if xmlType._children[0]._name == "ReferenceType":
......@@ -794,7 +794,7 @@ def GenericFactory(newModule: Module, xmlType: Element) -> AsnNode:
lineNo = GetAttr(xmlType, "Line")
global g_lineno
g_lineno = lineNo
if len(xmlType._children) == 0:
if len(xmlType._children) == 0: # pylint: disable=len-as-condition
utility.panic("GenericFactory: No children for Type (%s, %s)" % # pragma: no cover
(newModule._asnFilename, lineNo)) # pragma: no cover
xmlContainedType = xmlType._children[0]
......@@ -895,7 +895,7 @@ def SimpleCleaner(x: str) -> str:
def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[str], str]) -> None:
if len(xmlType._children) == 0:
if len(xmlType._children) == 0: # pylint: disable=len-as-condition
utility.panic("AST inconsistency: xmlType._children == 0\nContact ESA") # pragma: no cover
realType = xmlType._children[0]
if realType._name == "BooleanType":
......@@ -926,7 +926,7 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
def addNewOption(x: Any) -> None:
options.append(x)
VisitAll(realType, "EnumValue", addNewOption)
if len(options) > 0:
if options:
f.write(indent + ' ' + nameCleaner(GetAttr(options[0], "StringValue")) + "(" + GetAttr(options[0], "IntValue") + ")")
for otherOptions in options[1:]:
f.write(',\n' + indent + ' ' + nameCleaner(GetAttr(otherOptions, "StringValue")) + "(" + GetAttr(otherOptions, "IntValue") + ")")
......@@ -936,10 +936,10 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
f.write('SEQUENCE {\n')
else:
f.write('SET {\n')
if len(realType._children) > 0:
if len(realType._children) > 0: # pylint: disable=len-as-condition
f.write(indent + ' ' + nameCleaner(GetAttr(realType._children[0], "VarName")) + "\t")
firstChildOptional = GetAttr(realType._children[0], "Optional") == "True"
if len(realType._children[0]._children) == 0:
if len(realType._children[0]._children) == 0: # pylint: disable=len-as-condition
utility.panic("AST inconsistency: len(realType._children[0]._children) = 0\nContact ESA") # pragma: no cover
PrintType(f, realType._children[0]._children[0], indent + " ", nameCleaner) # the contained type of the first child
if firstChildOptional:
......@@ -947,7 +947,7 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
for sequenceOrSetChild in realType._children[1:]:
f.write(",\n" + indent + ' ' + nameCleaner(GetAttr(sequenceOrSetChild, "VarName")) + "\t")
childOptional = GetAttr(sequenceOrSetChild, "Optional") == "True"
if len(sequenceOrSetChild._children) == 0:
if len(sequenceOrSetChild._children) == 0: # pylint: disable=len-as-condition
utility.panic("AST inconsistency: len(sequenceOrSetChild._children) = 0\nContact ESA") # pragma: no cover
PrintType(f, sequenceOrSetChild._children[0], indent + " ", nameCleaner) # the contained type
if childOptional:
......@@ -957,14 +957,14 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
f.write('\n' + indent + '}')
elif realType._name == "ChoiceType":
f.write('CHOICE {\n')
if len(realType._children) > 0:
if len(realType._children) > 0: # pylint: disable=len-as-condition
f.write(indent + ' ' + nameCleaner(GetAttr(realType._children[0], "VarName")) + "\t")
if len(realType._children[0]._children) == 0:
if len(realType._children[0]._children) == 0: # pylint: disable=len-as-condition
utility.panic("AST inconsistency: len(realType._children[0]._children) = 0\nContact ESA") # pragma: no cover
PrintType(f, realType._children[0]._children[0], indent + " ", nameCleaner) # the contained type of the first child
for choiceChild in realType._children[1:]:
f.write(",\n" + indent + ' ' + nameCleaner(GetAttr(choiceChild, "VarName")) + "\t")
if len(choiceChild._children) == 0:
if len(choiceChild._children) == 0: # pylint: disable=len-as-condition
utility.panic("AST inconsistency: len(choiceChild._children) = 0\nContact ESA") # pragma: no cover
PrintType(f, choiceChild._children[0], indent + " ", nameCleaner) # the contained type
else:
......@@ -975,7 +975,7 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
mmin = GetAttr(realType, "Min")
mmax = GetAttr(realType, "Max")
f.write(' (SIZE (%s .. %s)) OF ' % (mmin, mmax))
if len(realType._children) > 0:
if len(realType._children) > 0: # pylint: disable=len-as-condition
PrintType(f, realType._children[0], indent + " ", nameCleaner) # the contained type
else:
utility.panic("AST inconsistency: len(realType._children)=0\nContact ESA") # pragma: no cover
......@@ -984,7 +984,7 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
mmin = GetAttr(realType, "Min")
mmax = GetAttr(realType, "Max")
f.write(' (SIZE (%s .. %s)) OF ' % (mmin, mmax))
if len(realType._children) > 0:
if len(realType._children) > 0: # pylint: disable=len-as-condition
PrintType(f, realType._children[0], indent + " ", nameCleaner) # the contained type
else:
utility.panic("AST inconsistency: len(realType._children)=0\nContact ESA") # pragma: no cover
......@@ -992,7 +992,7 @@ def PrintType(f: IO[Any], xmlType: Element, indent: str, nameCleaner: Callable[[
utility.panic("AST inconsistency: Unknown type (%s)\nContact ESA" % realType._name) # pragma: no cover
def PrintGrammarFromAST(f: IO[Any], nameCleaner: Callable[[str], str]=SimpleCleaner) -> None:
def PrintGrammarFromAST(f: IO[Any], nameCleaner: Callable[[str], str] = SimpleCleaner) -> None:
ourtypeAssignments = []
VisitAll(
g_xmlASTrootNode._children[0], "Asn1File",
......
......@@ -64,7 +64,7 @@ def DiscoverBadTypes() -> SetOfBadTypenames:
# Hack for IA5Strings (IA5s are used in TASTE's runtime configuration spec)
while True:
foundOne = False
for nodeTypename in names.keys():
for nodeTypename in names:
nodeAST = names[nodeTypename]
if nodeTypename not in badTypes and CheckNodeForIA5(nodeAST):
badTypes.add(nodeTypename)
......
import re
import sys
from lxml import etree
from typing import List, Union, Optional, Any, Tuple, Dict, NoReturn # NOQA pylint: disable=unused-import
from lxml import etree
from .asnAST import (
AsnBool, AsnInt, AsnReal, AsnEnumerated, AsnOctetString, AsnSequenceOf,
AsnSet, AsnSetOf, AsnSequence, AsnChoice, AsnMetaMember, AsnNode)
......@@ -86,7 +86,7 @@ def info(level: int, *args: Any) -> None:
return
def panic(x: str, coloredBanner: str="") -> NoReturn:
def panic(x: str, coloredBanner: str = "") -> NoReturn:
"""Notifies the user that something fatal happened and aborts. """
info(0, yellow + coloredBanner + white + '\n' + x)
sys.exit(1)
......
......@@ -60,7 +60,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=coerce-method,nonzero-method,buffer-builtin,unichr-builtin,reload-builtin,using-cmp-argument,reduce-builtin,filter-builtin-not-iterating,zip-builtin-not-iterating,raising-string,long-builtin,backtick,long-suffix,delslice-method,suppressed-message,cmp-method,old-octal-literal,basestring-builtin,metaclass-assignment,print-statement,execfile-builtin,round-builtin,oct-method,standarderror-builtin,hex-method,import-star-module-level,indexing-exception,map-builtin-not-iterating,old-ne-operator,setslice-method,input-builtin,apply-builtin,range-builtin-not-iterating,xrange-builtin,parameter-unpacking,no-absolute-import,old-raise-syntax,dict-iter-method,unicode-builtin,unpacking-in-except,old-division,file-builtin,next-method-called,useless-suppression,raw_input-builtin,intern-builtin,getslice-method,dict-view-method,cmp-builtin,coerce-builtin,line-too-long,missing-docstring,protected-access,global-statement,too-many-arguments,too-many-branches,too-many-locals,bare-except,invalid-name,too-many-statements,broad-except,too-many-instance-attributes,too-many-public-methods,too-few-public-methods,similarities,no-else-return
disable=coerce-method,nonzero-method,buffer-builtin,unichr-builtin,reload-builtin,using-cmp-argument,reduce-builtin,filter-builtin-not-iterating,zip-builtin-not-iterating,raising-string,long-builtin,backtick,long-suffix,delslice-method,suppressed-message,cmp-method,old-octal-literal,basestring-builtin,metaclass-assignment,print-statement,execfile-builtin,round-builtin,oct-method,standarderror-builtin,hex-method,import-star-module-level,indexing-exception,map-builtin-not-iterating,old-ne-operator,setslice-method,input-builtin,apply-builtin,range-builtin-not-iterating,xrange-builtin,parameter-unpacking,no-absolute-import,old-raise-syntax,dict-iter-method,unicode-builtin,unpacking-in-except,old-division,file-builtin,next-method-called,useless-suppression,raw_input-builtin,intern-builtin,getslice-method,dict-view-method,cmp-builtin,coerce-builtin,line-too-long,missing-docstring,protected-access,global-statement,too-many-arguments,too-many-branches,too-many-locals,bare-except,invalid-name,too-many-statements,broad-except,too-many-instance-attributes,too-many-public-methods,too-few-public-methods,similarities,no-else-return,fixme
never-returning-functions=dmt.commonPy.utility.panic,sys.exit
......
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