Fixed method decorators with callable and opov
@@ -833,7 +833,12 @@ class Generator (ast.NodeVisitor):
def pushDecorator (self, node):
if node.decorator_list:
- self.classDecorators.insert (0, (node, self.scopes[1:]))
+ context = {
+ 'node': node,
+ 'scopes': self.scopes [1:],
+ 'opov': self.allowOperatorOverloading
+ }
+ self.classDecorators.insert (0, context)
def emitDecorators (self, callable=None):
@@ -877,31 +882,34 @@ class Generator (ast.NodeVisitor):
emitDecorator (callable.name, callable.name, decorator)
else:
while self.classDecorators:
- node, scopes = self.classDecorators.pop ()
+ context = self.classDecorators.pop ()
+ oldOpov = self.allowOperatorOverloading
+ self.allowOperatorOverloading = context ['opov']
- if type (node) in (ast.FunctionDef, ast.AsyncFunctionDef):
- sourceName = '__impl__{}'.format (node.name)
+ if type (context['node']) in (ast.FunctionDef, ast.AsyncFunctionDef):
+ sourceName = '__impl__{}'.format (context ['node'].name)
else:
- sourceName = node.name
+ sourceName = context ['node'].name
targetName = sourceName
- if scopes:
- for scope in scopes:
+ if context ['scopes']:
+ for scope in context ['scopes']:
self.inscope (scope.node)
classList = '.'.join ([_scope.node.name for _scope in self.getAdjacentClassScopes ()])
if classList:
targetName = '{}.{}'.format (classList, targetName)
- for decorator in reversed (node.decorator_list):
- if type (decorator) == ast.Name:
- if decorator.id not in ('classmethod', 'staticmethod'):
- emitDecorator (sourceName, targetName, decorator)
- else:
+ for decorator in reversed (context ['node'].decorator_list):
+ if not (type (decorator) == ast.Name and decorator.id in ('classmethod', 'staticmethod')):
emitDecorator (sourceName, targetName, decorator)
+ if classList:
+ self.emit (';')
- for scope in scopes:
+ for _ in range(len(context ['scopes'])):
self.descope ()
+ self.allowOperatorOverloading = oldOpov
+
def nextTemp (self, name):
if name in self.tempIndices:
self.tempIndices [name] += 1
@@ -2133,15 +2141,24 @@ class Generator (ast.NodeVisitor):
self.emit ('\n')
self.adaptLineNrString (node)
- if node.decorator_list:
- decorate = bool([d for d in node.decorator_list if d.id not in ('classmethod', 'staticmethod')])
- isClassMethod = bool([d for d in node.decorator_list if d.id == 'classmethod'])
- isStaticMethod = bool([d for d in node.decorator_list if d.id == 'staticmethod'])
- else:
decorate = False
isClassMethod = False
isStaticMethod = False
+ if node.decorator_list:
+ for decorator in node.decorator_list:
+ if type(decorator) == ast.Name:
+ nameCheck = decorator.id
+ elif type(decorator) == ast.Call:
+ nameCheck = decorator.func.id
+
+ if nameCheck == 'classmethod':
+ isClassMethod = True
+ elif nameCheck == 'staticmethod':
+ isStaticMethod = True
+ else:
+ decorate = True
+
if decorate:
implName = '__impl__{}'.format(node.name)
self.emit ('{}: {}function', implName, 'async ' if async else '')
