- Removed unused _str types
- Tested with untyped function arguments, seems to work a bit
This commit is contained in:
Johan B.W. de Vries 2022-11-27 12:33:17 +01:00
parent 30a4cee5af
commit a838035e1a
2 changed files with 12 additions and 19 deletions

View File

@ -224,22 +224,20 @@ class FunctionParam:
""" """
A parameter for a Function A parameter for a Function
""" """
__slots__ = ('name', 'type3', 'type_str', ) __slots__ = ('name', 'type3', )
name: str name: str
type3: Type3 type3: Type3OrPlaceholder
type_str: str
def __init__(self, name: str, type3: Type3) -> None: def __init__(self, name: str, type3: Optional[Type3]) -> None:
self.name = name self.name = name
self.type3 = type3 self.type3 = PlaceholderForType([self]) if type3 is None else type3
self.type_str = type3.name
class Function: class Function:
""" """
A function processes input and produces output A function processes input and produces output
""" """
__slots__ = ('name', 'lineno', 'exported', 'imported', 'statements', 'returns_type3', 'returns_str', 'posonlyargs', ) __slots__ = ('name', 'lineno', 'exported', 'imported', 'statements', 'returns_type3', 'posonlyargs', )
name: str name: str
lineno: int lineno: int
@ -247,7 +245,6 @@ class Function:
imported: bool imported: bool
statements: List[Statement] statements: List[Statement]
returns_type3: Type3 returns_type3: Type3
returns_str: str
posonlyargs: List[FunctionParam] posonlyargs: List[FunctionParam]
def __init__(self, name: str, lineno: int) -> None: def __init__(self, name: str, lineno: int) -> None:
@ -256,8 +253,7 @@ class Function:
self.exported = False self.exported = False
self.imported = False self.imported = False
self.statements = [] self.statements = []
self.returns_type3 = type3types.none self.returns_type3 = type3types.none # FIXME: This could be a placeholder
self.returns_str = 'None'
self.posonlyargs = [] self.posonlyargs = []
class StructDefinition: class StructDefinition:
@ -319,12 +315,11 @@ class ModuleConstantDef:
""" """
A constant definition within a module A constant definition within a module
""" """
__slots__ = ('name', 'lineno', 'type3', 'type_str', 'constant', 'data_block', ) __slots__ = ('name', 'lineno', 'type3', 'constant', 'data_block', )
name: str name: str
lineno: int lineno: int
type3: Type3 type3: Type3
type_str: str
constant: Constant constant: Constant
data_block: Optional['ModuleDataBlock'] data_block: Optional['ModuleDataBlock']
@ -332,7 +327,6 @@ class ModuleConstantDef:
self.name = name self.name = name
self.lineno = lineno self.lineno = lineno
self.type3 = type3 self.type3 = type3
self.type_str = type3.name
self.constant = constant self.constant = constant
self.data_block = data_block self.data_block = data_block

View File

@ -119,12 +119,9 @@ class OurVisitor:
_not_implemented(not node.args.posonlyargs, 'FunctionDef.args.posonlyargs') _not_implemented(not node.args.posonlyargs, 'FunctionDef.args.posonlyargs')
for arg in node.args.args: for arg in node.args.args:
if not arg.annotation:
_raise_static_error(node, 'Type is required')
function.posonlyargs.append(FunctionParam( function.posonlyargs.append(FunctionParam(
arg.arg, arg.arg,
self.visit_type(module, arg.annotation), self.visit_type(module, arg.annotation) if arg.annotation else None,
)) ))
_not_implemented(not node.args.vararg, 'FunctionDef.args.vararg') _not_implemented(not node.args.vararg, 'FunctionDef.args.vararg')
@ -147,9 +144,11 @@ class OurVisitor:
else: else:
function.imported = True function.imported = True
if node.returns: if node.returns is not None: # Note: `-> None` would be a ast.Constant
function.returns_type3 = self.visit_type(module, node.returns) function.returns_type3 = self.visit_type(module, node.returns)
function.returns_str = function.returns_type3.name else:
# Mostly works already, needs to fix Function.returns_type3 and have it updated
raise NotImplementedError('Function without an explicit return type')
_not_implemented(not node.type_comment, 'FunctionDef.type_comment') _not_implemented(not node.type_comment, 'FunctionDef.type_comment')