Commit 2d56fd54 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

[mypy] Only pyside_B_mapper remains for 100% pass

This is with using mypy in "default checks" mode, i.e. via:

    mypy --check-untyped-defs

Further annotations will be added of course, strengthening type-safety
even more beyond the "defaults" identified with mypy type-inference.
parent 0a85aa5b
......@@ -139,8 +139,7 @@ def OnStartup(unused_modelingLanguage: str, asnFile: str, outputDir: str, badTyp
# mono_exe = "mono " if sys.argv[0].endswith('.py') and sys.platform.startswith('linux') else ""
mono_exe = ""
makefile.write(
'''\
makefile_text = '''\
ASN1SCC:=asn1.exe
ASN2DATAMODEL:=asn2dataModel
GRAMMAR := %(origGrammarBase)s
......@@ -172,7 +171,8 @@ clean:
%(tab)srm -f $(BDIR)/asn1crt.? $(BDIR)/real.? $(BDIR)/$(GRAMMAR).? $(BDIR)/acn.? $(BDIR)/ber.? $(BDIR)/xer.?
%(tab)srm -f $(BDIR)/DV.py $(BDIR)/*.pyc $(BDIR)/$(BASEGRAMMAR)_getset.? $(BDIR)/$(BASEGRAMMAR)_getset.so
%(tab)srm -f $(BDIR)/$(GRAMMAR)_asn.py
''' % {'tab': '\t', 'base': base, 'origGrammarBase': origGrammarBase, 'mono': mono_exe})
'''
makefile.write(makefile_text % {'tab': '\t', 'base': base, 'origGrammarBase': origGrammarBase, 'mono': mono_exe})
makefile.close()
CreateDeclarationsForAllTypes(asnParser.g_names, asnParser.g_leafTypeDict, badTypes)
g_outputGetSetH.write('\n/* Helper functions for NATIVE encodings */\n\n')
......
......@@ -15,8 +15,8 @@ g_PyDataModel = None
g_iter = 1
g_IFCount = 0
g_BackendFile = None
g_fromPysideToASN1 = []
g_fromASN1ToPyside = []
g_fromPysideToASN1 = [] # type: List[str]
g_fromASN1ToPyside = [] # type: List[str]
g_QUiFile = None
g_bStarted = False
g_firstElem = True
......
......@@ -316,7 +316,7 @@ def ConvertCatalogueToASN_AST(inputSmp2Files):
# Do a first pass, verifying the primary assumption:
# That 'Id' elements of types are unique across our set of SMP2 files.
for inputSmp2File in inputSmp2Files:
a = etree.parse(open(inputSmp2File))
a = etree.parse(open(inputSmp2File)) # type: Any # mypy bugs in ElementTree handling
root = a.getroot()
if len(root) < 1 or not root.tag.endswith('Catalogue'):
panic('', "You must use an XML file that contains an SMP2 Catalogue") # pragma: no cover
......
......@@ -32,9 +32,11 @@ import os
import sys
import getopt
from typing import Dict
from .commonPy import asnParser
from .commonPy.createInternalTypes import ScanChildren
from .commonPy.asnAST import AsnMetaType
from .commonPy.asnParser import AST_Lookup # NOQA pylint: disable=unused-import
from .commonPy.commonSMP2 import (
info, panic, green, white, red, setVerbosity,
DashUnderscoreAgnosticDict, ConvertCatalogueToASN_AST)
......@@ -55,12 +57,12 @@ def usage(coloredMsg=""):
panic(usageMsg, coloredMsg)
def MergeASN1_AST(smp2AsnAST):
def MergeASN1_AST(smp2AsnAST) -> Dict[str, str]:
'''Merges the ASN.1 AST generated from SMP2 files (smp2AsnAST param)
into the ASN.1 AST stored in asnParser.g_names. Uses smart
merging, i.e. diff-like semantics.'''
typesToAddVerbatim = []
identicals = {}
identicals = {} # type: Dict[str, str]
d = asnParser.g_names
for k, v in smp2AsnAST.items():
if k in d:
......@@ -96,14 +98,15 @@ def MergeASN1_AST(smp2AsnAST):
for r in results:
node = smp2AsnAST[r]
d[r] = node
if isinstance(node, AsnMetaType):
asnParser.g_metatypes[r] = r._containedType # pragma: no cover
d[r] = smp2AsnAST[r._containedType] # pragma: no cover
# mypy helped me see that his is impossible (coverage agrees - notice the no cover!)
# if isinstance(node, AsnMetaType):
# asnParser.g_metatypes[r] = r._containedType # pragma: no cover
# d[r] = smp2AsnAST[r._containedType] # pragma: no cover
asnParser.g_typesOfFile.setdefault(node._asnFilename, []).append(r)
return identicals
def SaveASN_AST(bPruneUnnamedInnerTASTEtypes, outputAsn1Grammar, identicals):
def SaveASN_AST(bPruneUnnamedInnerTASTEtypes: bool, outputAsn1Grammar: str, identicals: Dict[str, str]):
d = DashUnderscoreAgnosticDict()
for k, v in asnParser.g_names.items():
d[k] = v
......@@ -124,8 +127,8 @@ def SaveASN_AST(bPruneUnnamedInnerTASTEtypes, outputAsn1Grammar, identicals):
f.write('-- From ' + v._asnFilename + ' line ' + str(v._lineno) + '\n')
f.write(k + ' ::= ')
f.write(v.AsASN1(d) + "\n\n")
for k, v in identicals.items():
f.write(k + ' ::= ' + v + '\n\n')
for k2, v2 in identicals.items():
f.write(k2 + ' ::= ' + v2 + '\n\n')
f.write('END\n')
......
Supports Markdown
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