Commit de32481f authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Prepare for Mypy

parent ebc2ca84
......@@ -295,10 +295,7 @@ asn2dataModel -toPython dataview-uniq.asn
make -f Makefile.python
echo "errCodes=$(taste-asn1-errCodes ./dataview-uniq.h)" >>datamodel.py
LD_LIBRARY_PATH=./lib:. opengeode-simulator
'''.format(pr=process_name.lower(),
asn1_files=asn1_filenames,
asn1_mod=' '.join(asn1_modules_o))
'''.format(pr=process_name.lower())
LOG.info('Generating Ada code for process ' + str(process_name))
......@@ -2427,7 +2424,7 @@ def _boolean(primary, **kwargs):
@expression.register(ogAST.PrimNull)
def _boolean(primary, **kwargs):
def _null(primary, **kwargs):
''' Generate code for a raw null value '''
ada_string = '0'
return [], str(ada_string), []
......@@ -2670,7 +2667,6 @@ def _choiceitem(choice, **kwargs):
prefix = basic.Children[each].EnumID
break
ada_string = u'(Kind => {kind}, {opt} => {expr})'.format(
cType=type_name(choice.exprType),
kind=prefix,
opt=choice.value['choice'],
expr=choice_str)
......
......@@ -434,7 +434,7 @@ class Channel(Signalroute):
return self._start_point
@start_point.setter
def start_point(self, scene_coord): # type: QPointF
def start_point(self, scene_coord : QPointF):
''' value is in scene coordinates '''
self._start_point = self.parent.mapFromScene(scene_coord)
......@@ -444,7 +444,7 @@ class Channel(Signalroute):
return self.parent.mapFromScene(self._end_point)
@end_point.setter
def end_point(self, scene_coord): # type: QPointF
def end_point(self, scene_coord : QPointF):
''' value is in scene coordinates '''
self._end_point = scene_coord
......
......@@ -512,13 +512,13 @@ def _rename_prim_seq_of(ast, from_name, to_name):
rename_everything(each, from_name, to_name)
@rename_everything.register(ogAST.PrimSequence)
def _rename_prim_seq_of(ast, from_name, to_name):
def _rename_prim_seq(ast, from_name, to_name):
''' Values in the fields of a SEQUENCE '''
for each in ast.value.values():
rename_everything(each, from_name, to_name)
@rename_everything.register(ogAST.PrimChoiceItem)
def _rename_prim_seq_of(ast, from_name, to_name):
def _rename_prim_choice_item(ast, from_name, to_name):
''' Value of a CHOICE item '''
rename_everything(ast.value['value'], from_name, to_name)
......
......@@ -401,7 +401,7 @@ def _procedure(symbol, recursive=True, **kwargs):
Indent.indent += 1
result.extend(parse_scene(symbol.nested_scene))
Indent.indent -= 1
result.append(u'endprocedure;'.format(str(symbol)))
result.append('endprocedure;')
return result
......
......@@ -436,9 +436,4 @@ class EditableText(QGraphicsTextItem):
def __str__(self):
''' Print the text inside the symbol '''
raise TypeError('Use UNICODE, not string!')
def __str__(self):
return self.toPlainText()
......@@ -246,11 +246,11 @@ class Symbol(QObject, QGraphicsPathItem):
def conn_end_zones(self):
return []
def in_start_zone(self, point): # type: QPoint
def in_start_zone(self, point: QPoint) -> bool:
''' Return true if "point" is in one of the connection start zones '''
return any(rect.contains(point) for rect in self.conn_start_zones)
def in_end_zone(self, point): # type: QPoint
def in_end_zone(self, point: QPoint) -> bool:
''' Return true if "point" is in one of the connection end zones '''
return any(rect.contains(point) for rect in self.conn_end_zones)
......
......@@ -124,11 +124,7 @@ class ExprLe(Expression):
class ExprDiv(Expression):
operand = '/'
try:
op = operator.div
except AttributeError:
# for Python3:
op = operator.truediv
op = operator.truediv # python3 only
class ExprMod(Expression):
......
......@@ -32,6 +32,7 @@ import operator
import logging
import traceback
import codecs
from typing import Dict, Tuple
from inspect import currentframe, getframeinfo
import binascii
from textwrap import dedent
......@@ -49,7 +50,7 @@ from .Asn1scc import parse_asn1, ASN1, create_choice_determinant_types
LOG = logging.getLogger(__name__)
EXPR_NODE = {
EXPR_NODE: Dict[int, ogAST.Expression] = {
lexer.PLUS: ogAST.ExprPlus,
lexer.ASTERISK: ogAST.ExprMul,
lexer.IMPLIES: ogAST.ExprImplies,
......@@ -71,7 +72,7 @@ EXPR_NODE = {
lexer.NOT: ogAST.ExprNot,
lexer.NEG: ogAST.ExprNeg,
lexer.PRIMARY: ogAST.Primary,
} # type: Dict[int, ogAST.Expression]
}
# Insert current path in the search list for importing modules
sys.path.insert(0, '.')
......@@ -212,8 +213,7 @@ def set_global_DV(asn1_filenames):
raise TypeError('ASN.1 compiler failed - {}'.format(str(err)))
def substring_range(substring):
# type: (ogAST.PrimSubstring) -> Tuple[str, str]
def substring_range(substring: ogAST.PrimSubString) -> Tuple[str, str]:
''' Return the range of a substring '''
left, right = substring.value[1]['substring']
left_bty = find_basic_type(left.exprType)
......@@ -221,13 +221,12 @@ def substring_range(substring):
return left_bty.Min, right_bty.Max
def is_number(basic_ty):
def is_number(basic_ty) -> bool:
''' Return true if basic type is a raw number (i.e. not a variable) '''
return basic_ty.__name__ in ('Universal_Integer', 'PrReal')
def is_integer(ty):
# type: (Any) -> bool
def is_integer(ty) -> bool:
''' Return true if a type is an Integer Type '''
return find_basic_type(ty).kind in (
'IntegerType',
......@@ -235,14 +234,12 @@ def is_integer(ty):
)
def is_real(ty):
# type: (Any) -> bool
def is_real(ty) -> bool:
''' Return true if a type is a Real Type '''
return find_basic_type(ty).kind == 'RealType'
def is_numeric(ty):
# type: (Any) -> bool
def is_numeric(ty) -> bool:
''' Return true if a type is a Numeric Type '''
return find_basic_type(ty).kind in (
'IntegerType',
......@@ -252,20 +249,17 @@ def is_numeric(ty):
)
def is_boolean(ty):
# type: (Any) -> bool
def is_boolean(ty) -> bool:
''' Return true if a type is a Boolean Type '''
return find_basic_type(ty).kind == 'BooleanType'
def is_null(ty):
# type: (Any) -> bool
def is_null(ty) -> bool:
''' Return true if a type is a NULL Type '''
return find_basic_type(ty).kind == 'NullType'
def is_string(ty):
# type: (Any) -> bool
def is_string(ty) -> bool:
''' Return true if a type is a String Type '''
return find_basic_type(ty).kind in (
'StandardStringType',
......@@ -274,43 +268,37 @@ def is_string(ty):
)
def is_sequenceof(ty):
# type: (Any) -> bool
def is_sequenceof(ty) -> bool:
''' Return true if a type is a SequenceOf Type '''
return find_basic_type(ty).kind == 'SequenceOfType'
def is_list(ty):
# type: (Any) -> bool
def is_list(ty) -> bool:
''' Return true if a type is a List Type '''
return is_string(ty) or is_sequenceof(ty) or ty == LIST
def is_enumerated(ty):
# type: (Any) -> bool
def is_enumerated(ty) -> bool:
''' Return true if a type is an Enumerated Type '''
return find_basic_type(ty).kind == 'EnumeratedType' or ty == ENUMERATED
def is_sequence(ty):
# type: (Any) -> bool
def is_sequence(ty) -> bool:
''' Return true if a type is a Sequence Type '''
return find_basic_type(ty).kind == 'SequenceType'
def is_choice(ty):
# type: (Any) -> bool
def is_choice(ty) -> bool:
''' Return true if a type is a Choice Type '''
return find_basic_type(ty).kind == 'ChoiceType' or ty == CHOICE
def is_timer(ty):
# type: (Any) -> bool
def is_timer(ty) -> bool:
''' Return true if a type is a Timer Type '''
return find_basic_type(ty).kind == 'TimerType'
def sdl_to_asn1(sort):
def sdl_to_asn1(sort: str):
'''
Convert case insensitive type reference to the actual type as found
in the ASN.1 datamodel
......@@ -460,20 +448,17 @@ def get_input_string(root):
root.getTokenStopIndex())
def error(root, msg):
# type: (Any, str) -> str
def error(root, msg: str) -> str:
''' Return an error message '''
return '{} - "{}"'.format(msg, get_input_string(root))
def warning(root, msg):
# type: (Any, str) -> str
def warning(root, msg: str) -> str:
''' Return a warning message '''
return '{} - "{}"'.format(msg, get_input_string(root))
def tmp():
# type : () -> int
def tmp() -> int:
''' Return a temporary variable name '''
global TMPVAR
varname = TMPVAR
......@@ -887,7 +872,7 @@ def fix_append_expression_type(expr, expected_type):
expr.expected_type = expected_type
def check_type_compatibility(primary, type_ref, context): # type: -> [warnings]
def check_type_compatibility(primary, type_ref, context):
'''
Check if an ogAST.Primary (raw value, enumerated, ASN.1 Value...)
is compatible with a given type (type_ref is an ASN1Scc type)
......@@ -1251,7 +1236,7 @@ def fix_enumerated_and_choice(expr_enum, context):
return warnings
def fix_expression_types(expr, context): # type: -> [warnings]
def fix_expression_types(expr, context):
''' Check/ensure type consistency in binary expressions '''
warnings = []
for _ in range(2):
......
......@@ -414,8 +414,8 @@ class SDL_Scene(QGraphicsScene):
self.click_coordinates = None
self.orig_pos = None
# When connecting symbols, store list of intermediate points
self.edge_points = [] # type: List[QPointF] in scene coordinates
self.temp_lines = [] # type: List[QGraphicsLineItem]
self.edge_points = [] # type is List[QPointF] in scene coordinates
self.temp_lines = [] # type is List[QGraphicsLineItem]
self.process_name = 'opengeode'
# Scene name is used to update the tab window name when scene changes
self.name = ''
......
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