Commit 1faa2235 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

Better attempt to appease mypy.

parent e95c60e4
Pipeline #1764 failed with stage
in 22 seconds
...@@ -228,7 +228,7 @@ of each SUBPROGRAM param.''' ...@@ -228,7 +228,7 @@ of each SUBPROGRAM param.'''
panic(str(e)) panic(str(e))
def SpecialCodes(asnFile: str) -> None: def SpecialCodes(asnFile: Optional[str]) -> None:
'''This function handles the code generations needs that reside outside '''This function handles the code generations needs that reside outside
the scope of individual parameters (e.g. it needs access to all ASN.1 the scope of individual parameters (e.g. it needs access to all ASN.1
types). This used to cover Dumpable C/Ada Types and OG headers.''' types). This used to cover Dumpable C/Ada Types and OG headers.'''
...@@ -393,7 +393,7 @@ def ProcessAsync( # pylint: disable=dangerous-default-value ...@@ -393,7 +393,7 @@ def ProcessAsync( # pylint: disable=dangerous-default-value
def ProcessCustomBackends( def ProcessCustomBackends(
# Taking list of tuples made of (spName, sp_impl, language, maybeFVname) # Taking list of tuples made of (spName, sp_impl, language, maybeFVname)
asnFile: str, asnFile: Optional[str],
useOSS: bool, useOSS: bool,
SystemsAndImplementations: List[Tuple[str, str, str, str]]) -> None: SystemsAndImplementations: List[Tuple[str, str, str, str]]) -> None:
...@@ -430,6 +430,10 @@ def ProcessCustomBackends( ...@@ -430,6 +430,10 @@ def ProcessCustomBackends(
if lang.lower() == "vhdl": if lang.lower() == "vhdl":
workedOnVHDL = True # pragma: no cover workedOnVHDL = True # pragma: no cover
inform("Creating %s for %s.%s", lang.upper(), sp._id, sp_impl) inform("Creating %s for %s.%s", lang.upper(), sp._id, sp_impl)
# Necessary for mypy, but guaranteed by the check above for empty sp._params.
assert asnFile is not None
for backend in getCustomBackends(lang): for backend in getCustomBackends(lang):
backend.OnStartup(lang, asnFile, sp, sp_impl, commonPy.configMT.outputDir, maybeFVname, useOSS) backend.OnStartup(lang, asnFile, sp, sp_impl, commonPy.configMT.outputDir, maybeFVname, useOSS)
for param in sp._params: for param in sp._params:
...@@ -543,6 +547,7 @@ def main() -> None: ...@@ -543,6 +547,7 @@ def main() -> None:
uniqueDataFiles[param._signal._asnFilename].setdefault(sp._language, []) uniqueDataFiles[param._signal._asnFilename].setdefault(sp._language, [])
uniqueDataFiles[param._signal._asnFilename][sp._language].append(sp) uniqueDataFiles[param._signal._asnFilename][sp._language].append(sp)
asnFile = None # type: Optional[str]
asn1files = list(uniqueDataFiles.keys()) asn1files = list(uniqueDataFiles.keys())
if len(asn1files) == 1: if len(asn1files) == 1:
asnFile = asn1files[0] asnFile = asn1files[0]
...@@ -551,9 +556,10 @@ def main() -> None: ...@@ -551,9 +556,10 @@ def main() -> None:
elif asn1files: elif asn1files:
panic("There appear to be more than one ASN.1 files referenced (%s)..." % str(asn1files)) panic("There appear to be more than one ASN.1 files referenced (%s)..." % str(asn1files))
names = commonPy.asnParser.g_names if asnFile is not None:
for node in names.values(): names = commonPy.asnParser.g_names
verify.VerifyRanges(node, names) for node in names.values():
verify.VerifyRanges(node, names)
SystemsAndImplementations = commonPy.aadlAST.g_subProgramImplementations[:] SystemsAndImplementations = commonPy.aadlAST.g_subProgramImplementations[:]
SystemsAndImplementations.extend(commonPy.aadlAST.g_threadImplementations[:]) SystemsAndImplementations.extend(commonPy.aadlAST.g_threadImplementations[:])
...@@ -605,6 +611,9 @@ def main() -> None: ...@@ -605,6 +611,9 @@ def main() -> None:
if modelingLanguage.lower() in ["gui_ri", "gui_pi", "vhdl", "rhapsody"]: if modelingLanguage.lower() in ["gui_ri", "gui_pi", "vhdl", "rhapsody"]:
modelingLanguage = "C" modelingLanguage = "C"
# Necessary for mypy, but guaranteed by the check above for empty sp._params.
assert asnFile is not None
if modelingLanguage in async_languages: if modelingLanguage in async_languages:
m = ProcessAsync(modelingLanguage, asnFile, sp, maybeFVname, useOSS, badTypes) m = ProcessAsync(modelingLanguage, asnFile, sp, maybeFVname, useOSS, badTypes)
asynchronousBackends.add(m) asynchronousBackends.add(m)
...@@ -613,7 +622,9 @@ def main() -> None: ...@@ -613,7 +622,9 @@ def main() -> None:
# SystemsAndImplementation loop completed - time to call OnShutdown ONCE for each async backend that we loaded # SystemsAndImplementation loop completed - time to call OnShutdown ONCE for each async backend that we loaded
for asyncBackend in asynchronousBackends: for asyncBackend in asynchronousBackends:
asyncBackend.OnShutdown(modelingLanguage, asnFile, maybeFVname) # Appeasing mypy: asnFile can be None here, so I checked all
# B mappers - no-one depends on a None value for the asnFile.
asyncBackend.OnShutdown(modelingLanguage, '' if not asnFile else asnFile, maybeFVname)
ProcessCustomBackends(asnFile, useOSS, SystemsAndImplementations) ProcessCustomBackends(asnFile, useOSS, SystemsAndImplementations)
......
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