Run pyupgrade to clean up Python 2 syntaxes

Update all .py source files by
 $ pyupgrade --py3-only $(git ls-files | grep ".py$")
to modernize the code according to Python 3 syntaxes.

pep8 errors are fixed by
 $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \
    --in-place yaql

Change-Id: If8fe14ea056d30984669f4cb96098084c4d32e7c
This commit is contained in:
Takashi Kajinami 2024-10-21 22:03:14 +09:00
parent 82a1eb0076
commit c054a36e93
25 changed files with 169 additions and 183 deletions

View File

@ -33,7 +33,7 @@ def _get_modules_names(package):
return sorted( return sorted(
map(operator.itemgetter(1), map(operator.itemgetter(1),
pkgutil.walk_packages(package.__path__, pkgutil.walk_packages(package.__path__,
'{0}.'.format(package.__name__)))) '{}.'.format(package.__name__))))
def _get_functions_names(module): def _get_functions_names(module):
@ -89,7 +89,7 @@ def write_method_doc(method, output):
else: else:
call_as = 'function' call_as = 'function'
call_as_str = ' :callAs: {0}\n'.format(call_as) call_as_str = ' :callAs: {}\n'.format(call_as)
text = doc[:position] + call_as_str + doc[position:] text = doc[:position] + call_as_str + doc[position:]
except ValueError: except ValueError:
text = doc text = doc
@ -168,7 +168,7 @@ def generate_doc(source):
try: try:
package = importlib.import_module(source) package = importlib.import_module(source)
except ImportError: except ImportError:
return 'Error: No such module {0}'.format(source) return 'Error: No such module {}'.format(source)
out = io.StringIO() out = io.StringIO()
try: try:
if hasattr(package, '__path__'): if hasattr(package, '__path__'):
@ -179,7 +179,7 @@ def generate_doc(source):
return res return res
except Exception as e: except Exception as e:
return '.. code-block:: python\n\n Error: {0}\n {1}\n\n'.format( return '.. code-block:: python\n\n Error: {}\n {}\n\n'.format(
str(e), '\n '.join([''] + traceback.format_exc().split('\n'))) str(e), '\n '.join([''] + traceback.format_exc().split('\n')))
@ -188,7 +188,7 @@ class YaqlDocNode(nodes.General, nodes.Element):
def __init__(self, source): def __init__(self, source):
self.source = source self.source = source
super(YaqlDocNode, self).__init__() super().__init__()
class YaqlDocDirective(rst.Directive): class YaqlDocDirective(rst.Directive):

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
@ -34,8 +33,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'yaql' project = 'yaql'
copyright = u'2013, OpenStack Foundation' copyright = '2013, OpenStack Foundation'
# If true, '()' will be appended to :func: etc. cross-reference text. # If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True add_function_parentheses = True
@ -69,8 +68,8 @@ htmlhelp_basename = '%sdoc' % project
latex_documents = [ latex_documents = [
('index', ('index',
'%s.tex' % project, '%s.tex' % project,
u'%s Documentation' % project, '%s Documentation' % project,
u'OpenStack Foundation', 'manual'), 'OpenStack Foundation', 'manual'),
] ]
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
@ -55,8 +54,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'YAQL Release Notes' project = 'YAQL Release Notes'
copyright = u'2016, YAQL Developers' copyright = '2016, YAQL Developers'
# Release do not need a version number in the title, they # Release do not need a version number in the title, they
# cover multiple versions. # cover multiple versions.
@ -212,8 +211,8 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
('index', 'YaqlReleaseNotes.tex', u'Yaql Release Notes Documentation', ('index', 'YaqlReleaseNotes.tex', 'Yaql Release Notes Documentation',
u'Yaql Developers', 'manual'), 'Yaql Developers', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -242,8 +241,8 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
('index', 'yaqlreleasenotes', u'Yaql Release Notes Documentation', ('index', 'yaqlreleasenotes', 'Yaql Release Notes Documentation',
[u'Yaql Developers'], 1) ['Yaql Developers'], 1)
] ]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
@ -256,8 +255,8 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'YaqlReleaseNotes', u'Yaql Release Notes Documentation', ('index', 'YaqlReleaseNotes', 'Yaql Release Notes Documentation',
u'Yaql Developers', 'YaqlReleaseNotes', 'Yaql Developers', 'YaqlReleaseNotes',
'One line description of project.', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]

View File

@ -27,7 +27,7 @@ PROMPT = "yaql> "
def main(context, show_tokens, parser): def main(context, show_tokens, parser):
print("Yet Another Query Language - command-line query tool") print("Yet Another Query Language - command-line query tool")
print("Version {0}".format(version)) print("Version {}".format(version))
if context.get_data('legacy', False): if context.get_data('legacy', False):
print("Running in a legacy (0.2.x compatible) mode") print("Running in a legacy (0.2.x compatible) mode")
print("Copyright (c) 2013-2017 Mirantis, Inc") print("Copyright (c) 2013-2017 Mirantis, Inc")
@ -78,15 +78,15 @@ def main(context, show_tokens, parser):
res = expr.evaluate(context=context) res = expr.evaluate(context=context)
print_output(res, context) print_output(res, context)
except Exception as ex: except Exception as ex:
print(u'Execution exception: {0}'.format(ex), file=sys.stderr) print('Execution exception: {}'.format(ex), file=sys.stderr)
def load_data(data_file, context): def load_data(data_file, context):
try: try:
json_str = open(os.path.expanduser(data_file)).read() json_str = open(os.path.expanduser(data_file)).read()
except IOError as e: except OSError as e:
print("Unable to read data file '{0}': {1}".format(data_file, print("Unable to read data file '{}': {}".format(data_file,
e.strerror)) e.strerror))
return return
try: try:
data = json.loads(json_str) data = json.loads(json_str)
@ -94,7 +94,7 @@ def load_data(data_file, context):
print('Unable to parse data: ' + str(e)) print('Unable to parse data: ' + str(e))
return return
context['$'] = utils.convert_input_data(data) context['$'] = utils.convert_input_data(data)
print('Data from file {0} loaded into context'.format(data_file)) print('Data from file {} loaded into context'.format(data_file))
def register_in_context(context, parser): def register_in_context(context, parser):
@ -117,7 +117,7 @@ def evaluate(expr, parser, data, context):
res = parser(expr).evaluate(data, context) res = parser(expr).evaluate(data, context)
print_output(res, context) print_output(res, context)
except Exception as ex: except Exception as ex:
print(u'Execution exception: {0}'.format(ex), file=sys.stderr) print('Execution exception: {}'.format(ex), file=sys.stderr)
exit(1) exit(1)

View File

@ -98,7 +98,7 @@ class ContextBase(metaclass=abc.ABCMeta):
class Context(ContextBase): class Context(ContextBase):
def __init__(self, parent_context=None, data=utils.NO_VALUE, def __init__(self, parent_context=None, data=utils.NO_VALUE,
convention=None): convention=None):
super(Context, self).__init__(parent_context, convention) super().__init__(parent_context, convention)
self._functions = {} self._functions = {}
self._data = {} self._data = {}
self._exclusive_funcs = set() self._exclusive_funcs = set()
@ -186,12 +186,12 @@ class MultiContext(ContextBase):
filter(lambda t: t, map(lambda t: t.parent, context_list)) filter(lambda t: t, map(lambda t: t.parent, context_list))
) )
if not parents: if not parents:
super(MultiContext, self).__init__(None, convention) super().__init__(None, convention)
elif len(parents) == 1: elif len(parents) == 1:
super(MultiContext, self).__init__(parents[0], convention) super().__init__(parents[0], convention)
else: else:
super(MultiContext, self).__init__(MultiContext(parents), super().__init__(MultiContext(parents),
convention) convention)
def register_function(self, spec, *args, **kwargs): def register_function(self, spec, *args, **kwargs):
self._context_list[0].register_function(spec, *args, **kwargs) self._context_list[0].register_function(spec, *args, **kwargs)
@ -256,11 +256,11 @@ class LinkedContext(ContextBase):
def __init__(self, parent_context, linked_context, convention=None): def __init__(self, parent_context, linked_context, convention=None):
self.linked_context = linked_context self.linked_context = linked_context
if linked_context.parent: if linked_context.parent:
super(LinkedContext, self).__init__( super().__init__(
LinkedContext(parent_context, linked_context.parent, LinkedContext(parent_context, linked_context.parent,
convention), convention) convention), convention)
else: else:
super(LinkedContext, self).__init__(parent_context, convention) super().__init__(parent_context, convention)
def register_function(self, spec, *args, **kwargs): def register_function(self, spec, *args, **kwargs):
return self.linked_context.register_function(spec, *args, **kwargs) return self.linked_context.register_function(spec, *args, **kwargs)

View File

@ -31,79 +31,79 @@ class MethodResolutionError(ResolutionError):
class NoFunctionRegisteredException(FunctionResolutionError): class NoFunctionRegisteredException(FunctionResolutionError):
def __init__(self, name): def __init__(self, name):
super(NoFunctionRegisteredException, self).__init__( super().__init__(
u'Unknown function "{0}"'.format(name)) 'Unknown function "{}"'.format(name))
class NoMethodRegisteredException(MethodResolutionError): class NoMethodRegisteredException(MethodResolutionError):
def __init__(self, name, receiver): def __init__(self, name, receiver):
super(NoMethodRegisteredException, self).__init__( super().__init__(
u'Unknown method "{0}" for receiver {1}'.format(name, receiver)) 'Unknown method "{}" for receiver {}'.format(name, receiver))
class NoMatchingFunctionException(FunctionResolutionError): class NoMatchingFunctionException(FunctionResolutionError):
def __init__(self, name): def __init__(self, name):
super(NoMatchingFunctionException, self).__init__( super().__init__(
u'No function "{0}" matches supplied arguments'.format(name)) 'No function "{}" matches supplied arguments'.format(name))
class NoMatchingMethodException(MethodResolutionError): class NoMatchingMethodException(MethodResolutionError):
def __init__(self, name, receiver): def __init__(self, name, receiver):
super(NoMatchingMethodException, self).__init__( super().__init__(
u'No method "{0}" for receiver {1} matches ' 'No method "{}" for receiver {} matches '
u'supplied arguments'.format(name, receiver)) 'supplied arguments'.format(name, receiver))
class AmbiguousFunctionException(FunctionResolutionError): class AmbiguousFunctionException(FunctionResolutionError):
def __init__(self, name): def __init__(self, name):
super(AmbiguousFunctionException, self).__init__( super().__init__(
u'Ambiguous function "{0}"'.format(name)) 'Ambiguous function "{}"'.format(name))
class AmbiguousMethodException(MethodResolutionError): class AmbiguousMethodException(MethodResolutionError):
def __init__(self, name, receiver): def __init__(self, name, receiver):
super(AmbiguousMethodException, self).__init__( super().__init__(
u'Ambiguous method "{0}" for receiver {1}'.format(name, receiver)) 'Ambiguous method "{}" for receiver {}'.format(name, receiver))
class ArgumentException(YaqlException): class ArgumentException(YaqlException):
def __init__(self, argument_name): def __init__(self, argument_name):
self.parameter_name = argument_name self.parameter_name = argument_name
super(ArgumentException, self).__init__( super().__init__(
u'Invalid argument {0}'.format(argument_name)) 'Invalid argument {}'.format(argument_name))
class MappingTranslationException(YaqlException): class MappingTranslationException(YaqlException):
def __init__(self): def __init__(self):
super(MappingTranslationException, self).__init__( super().__init__(
u'Cannot convert mapping to keyword argument') 'Cannot convert mapping to keyword argument')
class ArgumentValueException(YaqlException): class ArgumentValueException(YaqlException):
def __init__(self): def __init__(self):
super(ArgumentValueException, self).__init__() super().__init__()
class DuplicateParameterDecoratorException(YaqlException): class DuplicateParameterDecoratorException(YaqlException):
def __init__(self, function_name, param_name): def __init__(self, function_name, param_name):
message = u"Function '{0}' has multiple " \ message = "Function '{0}' has multiple " \
u"decorators for parameter '{1}'". \ "decorators for parameter '{1}'". \
format(function_name, param_name) format(function_name, param_name)
super(DuplicateParameterDecoratorException, self).__init__(message) super().__init__(message)
class InvalidMethodException(YaqlException): class InvalidMethodException(YaqlException):
def __init__(self, function_name): def __init__(self, function_name):
message = u"Function '{0}' cannot be called as a method". \ message = "Function '{0}' cannot be called as a method". \
format(function_name) format(function_name)
super(InvalidMethodException, self).__init__(message) super().__init__(message)
class NoParameterFoundException(YaqlException): class NoParameterFoundException(YaqlException):
def __init__(self, function_name, param_name): def __init__(self, function_name, param_name):
message = u"Function '{0}' has no parameter called '{1}'". \ message = "Function '{0}' has no parameter called '{1}'". \
format(function_name, param_name) format(function_name, param_name)
super(NoParameterFoundException, self).__init__(message) super().__init__(message)
class YaqlParsingException(YaqlException): class YaqlParsingException(YaqlException):
@ -111,46 +111,46 @@ class YaqlParsingException(YaqlException):
self.value = value self.value = value
self.position = position self.position = position
self.message = message self.message = message
super(YaqlParsingException, self).__init__(message) super().__init__(message)
class YaqlGrammarException(YaqlParsingException): class YaqlGrammarException(YaqlParsingException):
def __init__(self, expr, value, position): def __init__(self, expr, value, position):
if position is None: if position is None:
msg = u'Parse error: unexpected end of statement' msg = 'Parse error: unexpected end of statement'
else: else:
msg = u"Parse error: unexpected '{0}' at position {1} of " \ msg = "Parse error: unexpected '{}' at position {} of " \
u"expression '{2}'".format(value, position, expr) "expression '{}'".format(value, position, expr)
super(YaqlGrammarException, self).__init__(value, position, msg) super().__init__(value, position, msg)
class YaqlLexicalException(YaqlParsingException): class YaqlLexicalException(YaqlParsingException):
def __init__(self, value, position): def __init__(self, value, position):
msg = u"Lexical error: illegal character '{0}' at position {1}" \ msg = "Lexical error: illegal character '{}' at position {}" \
.format(value, position) .format(value, position)
super(YaqlLexicalException, self).__init__(value, position, msg) super().__init__(value, position, msg)
class InvalidOperatorTableException(YaqlException): class InvalidOperatorTableException(YaqlException):
def __init__(self, op): def __init__(self, op):
super(InvalidOperatorTableException, self). \ super(). \
__init__(u"Invalid records in operator table for operator " __init__("Invalid records in operator table for operator "
u"'{0}".format(op)) "'{}".format(op))
class WrappedException(YaqlException): class WrappedException(YaqlException):
def __init__(self, exception): def __init__(self, exception):
self.wrapped = exception self.wrapped = exception
super(WrappedException, self).__init__(str(exception)) super().__init__(str(exception))
class CollectionTooLargeException(YaqlException): class CollectionTooLargeException(YaqlException):
def __init__(self, count): def __init__(self, count):
super(CollectionTooLargeException, self).__init__( super().__init__(
'Collection length exceeds {0} elements'.format(count)) 'Collection length exceeds {} elements'.format(count))
class MemoryQuotaExceededException(YaqlException): class MemoryQuotaExceededException(YaqlException):
def __init__(self): def __init__(self):
super(MemoryQuotaExceededException, self).__init__( super().__init__(
'Expression consumed too much memory') 'Expression consumed too much memory')

View File

@ -19,7 +19,7 @@ from yaql.language import exceptions
from yaql.language import utils from yaql.language import utils
class Expression(object): class Expression:
def __call__(self, receiver, context, engine): def __call__(self, receiver, context, engine):
pass pass
@ -34,7 +34,7 @@ class Function(Expression):
return context(self.name, engine, receiver, context)(*self.args) return context(self.name, engine, receiver, context)(*self.args)
def __str__(self): def __str__(self):
return '{0}({1})'.format(self.name, ', '.join(map(str, self.args))) return '{}({})'.format(self.name, ', '.join(map(str, self.args)))
class BinaryOperator(Function): class BinaryOperator(Function):
@ -44,7 +44,7 @@ class BinaryOperator(Function):
else: else:
func_name = '*' + alias func_name = '*' + alias
self.operator = op self.operator = op
super(BinaryOperator, self).__init__(func_name, obj1, obj2) super().__init__(func_name, obj1, obj2)
self.uses_receiver = False self.uses_receiver = False
@ -55,31 +55,31 @@ class UnaryOperator(Function):
else: else:
func_name = '*' + alias func_name = '*' + alias
self.operator = op self.operator = op
super(UnaryOperator, self).__init__(func_name, obj) super().__init__(func_name, obj)
self.uses_receiver = False self.uses_receiver = False
class IndexExpression(Function): class IndexExpression(Function):
def __init__(self, value, *args): def __init__(self, value, *args):
super(IndexExpression, self).__init__('#indexer', value, *args) super().__init__('#indexer', value, *args)
self.uses_receiver = False self.uses_receiver = False
class ListExpression(Function): class ListExpression(Function):
def __init__(self, *args): def __init__(self, *args):
super(ListExpression, self).__init__('#list', *args) super().__init__('#list', *args)
self.uses_receiver = False self.uses_receiver = False
class MapExpression(Function): class MapExpression(Function):
def __init__(self, *args): def __init__(self, *args):
super(MapExpression, self).__init__('#map', *args) super().__init__('#map', *args)
self.uses_receiver = False self.uses_receiver = False
class GetContextValue(Function): class GetContextValue(Function):
def __init__(self, path): def __init__(self, path):
super(GetContextValue, self).__init__('#get_context_data', path) super().__init__('#get_context_data', path)
self.path = path self.path = path
self.uses_receiver = False self.uses_receiver = False
@ -94,7 +94,7 @@ class Constant(Expression):
def __str__(self): def __str__(self):
if isinstance(self.value, str): if isinstance(self.value, str):
return "'{0}'".format(self.value) return "'{}'".format(self.value)
return str(self.value) return str(self.value)
def __call__(self, receiver, context, engine): def __call__(self, receiver, context, engine):
@ -124,7 +124,7 @@ class MappingRuleExpression(Expression):
self.uses_receiver = False self.uses_receiver = False
def __str__(self): def __str__(self):
return u'{0} => {1}'.format(self.source, self.destination) return '{} => {}'.format(self.source, self.destination)
def __call__(self, receiver, context, engine): def __call__(self, receiver, context, engine):
return utils.MappingRule( return utils.MappingRule(
@ -137,14 +137,14 @@ class Statement(Function):
self.expression = expression self.expression = expression
self.uses_receiver = False self.uses_receiver = False
self.engine = engine self.engine = engine
super(Statement, self).__init__('#finalize', expression) super().__init__('#finalize', expression)
def __call__(self, receiver, context, engine): def __call__(self, receiver, context, engine):
if not context.collect_functions('#finalize'): if not context.collect_functions('#finalize'):
context = context.create_child_context() context = context.create_child_context()
context.register_function(lambda x: x, name='#finalize') context.register_function(lambda x: x, name='#finalize')
try: try:
return super(Statement, self).__call__(receiver, context, engine) return super().__call__(receiver, context, engine)
except exceptions.WrappedException as e: except exceptions.WrappedException as e:
raise e.wrapped.with_traceback(sys.exc_info()[2]) raise e.wrapped.with_traceback(sys.exc_info()[2])

View File

@ -39,13 +39,13 @@ OperatorType = collections.namedtuple('OperatorType', [
) )
class YaqlOperators(object): class YaqlOperators:
def __init__(self, operators, name_value_op=None): def __init__(self, operators, name_value_op=None):
self.operators = operators self.operators = operators
self.name_value_op = name_value_op self.name_value_op = name_value_op
class YaqlEngine(object): class YaqlEngine:
def __init__(self, ply_lexer, ply_parser, options, factory): def __init__(self, ply_lexer, ply_parser, options, factory):
self._lexer = ply_lexer self._lexer = ply_lexer
self._parser = ply_parser self._parser = ply_parser
@ -81,7 +81,7 @@ class YaqlEngine(object):
return YaqlEngine(self._lexer, self._parser, opt, self._factory) return YaqlEngine(self._lexer, self._parser, opt, self._factory)
class YaqlFactory(object): class YaqlFactory:
def __init__(self, keyword_operator='=>', allow_delegates=False): def __init__(self, keyword_operator='=>', allow_delegates=False):
self._keyword_operator = keyword_operator self._keyword_operator = keyword_operator
self._allow_delegates = allow_delegates self._allow_delegates = allow_delegates
@ -156,7 +156,7 @@ class YaqlFactory(object):
position = i position = i
break break
if position < 0: if position < 0:
raise ValueError('Operator {0} is not found'.format( raise ValueError('Operator {} is not found'.format(
existing_operator)) existing_operator))
while position < len(self.operators) and len( while position < len(self.operators) and len(
self.operators[position]) > 1: self.operators[position]) > 1:

View File

@ -36,7 +36,7 @@ def decode_escapes(s):
# noinspection PyPep8Naming # noinspection PyPep8Naming
class Lexer(object): class Lexer:
t_ignore = ' \t\r\n' t_ignore = ' \t\r\n'
literals = '()],}' literals = '()],}'

View File

@ -19,7 +19,7 @@ from yaql.language import expressions
from yaql.language import utils from yaql.language import utils
class Parser(object): class Parser:
def __init__(self, lexer, yaql_operators, engine): def __init__(self, lexer, yaql_operators, engine):
self.tokens = lexer.tokens self.tokens = lexer.tokens
self._aliases = {} self._aliases = {}
@ -54,7 +54,7 @@ class Parser(object):
la.append(op_name) la.append(op_name)
binary_doc += (( binary_doc += ((
'value : ' if not binary_doc else '\n| ') + 'value : ' if not binary_doc else '\n| ') +
'value {0} value'.format(op_name)) 'value {} value'.format(op_name))
# noinspection PyProtectedMember # noinspection PyProtectedMember
def p_binary(this, p): def p_binary(this, p):

View File

@ -21,7 +21,7 @@ from yaql.language import yaqltypes
NO_DEFAULT = utils.create_marker('<NoValue>') NO_DEFAULT = utils.create_marker('<NoValue>')
class ParameterDefinition(object): class ParameterDefinition:
__slots__ = ('value_type', 'name', 'position', 'default', 'alias') __slots__ = ('value_type', 'name', 'position', 'default', 'alias')
def __init__(self, name, value_type=None, position=None, alias=None, def __init__(self, name, value_type=None, position=None, alias=None,
@ -33,7 +33,7 @@ class ParameterDefinition(object):
self.alias = alias self.alias = alias
def __repr__(self): def __repr__(self):
return '{0} => position={1} value_type={2} default={3}'.format( return '{} => position={} value_type={} default={}'.format(
self.name, self.position, self.value_type, self.default) self.name, self.position, self.value_type, self.default)
def clone(self): def clone(self):
@ -41,7 +41,7 @@ class ParameterDefinition(object):
self.position, self.alias, self.default) self.position, self.alias, self.default)
class FunctionDefinition(object): class FunctionDefinition:
__slots__ = ('is_method', 'is_function', 'name', 'parameters', 'payload', __slots__ = ('is_method', 'is_function', 'name', 'parameters', 'payload',
'doc', 'no_kwargs', 'meta') 'doc', 'no_kwargs', 'meta')
@ -461,7 +461,7 @@ def meta(name, value):
def yaql_property(source_type): def yaql_property(source_type):
def decorator(func): def decorator(func):
@name('#property#{0}'.format(get_function_definition(func).name)) @name('#property#{}'.format(get_function_definition(func).name))
@parameter('obj', source_type) @parameter('obj', source_type)
def wrapper(obj): def wrapper(obj):
return func(obj) return func(obj)

View File

@ -21,7 +21,7 @@ from yaql.language import lexer
def create_marker(msg): def create_marker(msg):
class MarkerClass(object): class MarkerClass:
def __repr__(self): def __repr__(self):
return msg return msg
return MarkerClass() return MarkerClass()
@ -113,7 +113,7 @@ def convert_tuples_to_lists(engine):
return engine.options.get('yaql.convertTuplesToLists', True) return engine.options.get('yaql.convertTuplesToLists', True)
class MappingRule(object): class MappingRule:
def __init__(self, source, destination): def __init__(self, source, destination):
self.source = source self.source = source
self.destination = destination self.destination = destination

View File

@ -62,7 +62,7 @@ class GenericType(SmartType):
__slots__ = ('checker', 'converter') __slots__ = ('checker', 'converter')
def __init__(self, nullable, checker=None, converter=None): def __init__(self, nullable, checker=None, converter=None):
super(GenericType, self).__init__(nullable) super().__init__(nullable)
self.checker = checker self.checker = checker
self.converter = converter self.converter = converter
@ -70,7 +70,7 @@ class GenericType(SmartType):
if isinstance(value, expressions.Constant): if isinstance(value, expressions.Constant):
value = value.value value = value.value
if not super(GenericType, self).check( if not super().check(
value, context, engine, *args, **kwargs): value, context, engine, *args, **kwargs):
return False return False
if value is None or isinstance(value, expressions.Expression): if value is None or isinstance(value, expressions.Expression):
@ -83,7 +83,7 @@ class GenericType(SmartType):
*args, **kwargs): *args, **kwargs):
if isinstance(value, expressions.Constant): if isinstance(value, expressions.Constant):
value = value.value value = value.value
super(GenericType, self).convert( super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
if value is None or not self.converter: if value is None or not self.converter:
return value return value
@ -102,7 +102,7 @@ class PythonType(GenericType):
validators = [validators] validators = [validators]
self.validators = validators self.validators = validators
super(PythonType, self).__init__( super().__init__(
nullable, nullable,
lambda value, context, *args, **kwargs: isinstance( lambda value, context, *args, **kwargs: isinstance(
value, self.python_type) and all( value, self.python_type) and all(
@ -127,14 +127,14 @@ class MappingRule(LazyParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(MappingRule, self).__init__(False) super().__init__(False)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return isinstance(value, expressions.MappingRuleExpression) return isinstance(value, expressions.MappingRuleExpression)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
super(MappingRule, self).convert( super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
wrap = lambda func: lambda: func(receiver, context, engine) # noqa wrap = lambda func: lambda: func(receiver, context, engine) # noqa
@ -145,11 +145,11 @@ class String(PythonType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False): def __init__(self, nullable=False):
super(String, self).__init__(str, nullable=nullable) super().__init__(str, nullable=nullable)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
value = super(String, self).convert( value = super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
return None if value is None else str(value) return None if value is None else str(value)
@ -158,7 +158,7 @@ class Integer(PythonType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False): def __init__(self, nullable=False):
super(Integer, self).__init__( super().__init__(
int, nullable=nullable, int, nullable=nullable,
validators=[lambda t: not isinstance(t, bool)]) validators=[lambda t: not isinstance(t, bool)])
@ -169,7 +169,7 @@ class DateTime(PythonType):
utctz = tz.tzutc() utctz = tz.tzutc()
def __init__(self, nullable=False): def __init__(self, nullable=False):
super(DateTime, self).__init__(datetime.datetime, nullable=nullable) super().__init__(datetime.datetime, nullable=nullable)
def convert(self, value, *args, **kwargs): def convert(self, value, *args, **kwargs):
if isinstance(value, datetime.datetime): if isinstance(value, datetime.datetime):
@ -177,14 +177,14 @@ class DateTime(PythonType):
return value.replace(tzinfo=self.utctz) return value.replace(tzinfo=self.utctz)
else: else:
return value return value
return super(DateTime, self).convert(value, *args, **kwargs) return super().convert(value, *args, **kwargs)
class Iterable(PythonType): class Iterable(PythonType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, validators=None, nullable=False): def __init__(self, validators=None, nullable=False):
super(Iterable, self).__init__( super().__init__(
collections.abc.Iterable, nullable, collections.abc.Iterable, nullable,
[lambda t: not isinstance(t, (str, utils.MappingType))] + ( [lambda t: not isinstance(t, (str, utils.MappingType))] + (
validators or [])) validators or []))
@ -193,12 +193,12 @@ class Iterable(PythonType):
if isinstance(value, utils.MappingType) and engine.options.get( if isinstance(value, utils.MappingType) and engine.options.get(
'yaql.iterableDicts', False): 'yaql.iterableDicts', False):
return True return True
return super(Iterable, self).check( return super().check(
value, context, engine, *args, **kwargs) value, context, engine, *args, **kwargs)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
res = super(Iterable, self).convert( res = super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
return None if res is None else utils.limit_iterable(res, engine) return None if res is None else utils.limit_iterable(res, engine)
@ -207,7 +207,7 @@ class Iterator(Iterable):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, validators=None, nullable=False): def __init__(self, validators=None, nullable=False):
super(Iterator, self).__init__( super().__init__(
validators=[utils.is_iterator] + (validators or []), validators=[utils.is_iterator] + (validators or []),
nullable=nullable) nullable=nullable)
@ -216,7 +216,7 @@ class Sequence(PythonType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, validators=None, nullable=False): def __init__(self, validators=None, nullable=False):
super(Sequence, self).__init__( super().__init__(
collections.abc.Sequence, nullable, [ collections.abc.Sequence, nullable, [
lambda t: not isinstance(t, (str, dict))] + ( lambda t: not isinstance(t, (str, dict))] + (
validators or [])) validators or []))
@ -226,7 +226,7 @@ class Number(PythonType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False): def __init__(self, nullable=False):
super(Number, self).__init__( super().__init__(
(int, float), nullable, (int, float), nullable,
validators=[lambda t: not isinstance(t, bool)]) validators=[lambda t: not isinstance(t, bool)])
@ -235,7 +235,7 @@ class Lambda(LazyParameterType, SmartType):
__slots__ = ('with_context', 'method') __slots__ = ('with_context', 'method')
def __init__(self, with_context=False, method=False): def __init__(self, with_context=False, method=False):
super(Lambda, self).__init__(True) super().__init__(True)
self.with_context = with_context self.with_context = with_context
self.method = method self.method = method
@ -243,7 +243,7 @@ class Lambda(LazyParameterType, SmartType):
if self.method and isinstance( if self.method and isinstance(
value, expressions.Expression) and not value.uses_receiver: value, expressions.Expression) and not value.uses_receiver:
return False return False
return super(Lambda, self).check(value, context, *args, **kwargs) return super().check(value, context, *args, **kwargs)
@staticmethod @staticmethod
def _publish_params(context, args, kwargs): def _publish_params(context, args, kwargs):
@ -264,7 +264,7 @@ class Lambda(LazyParameterType, SmartType):
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*convert_args, **convert_kwargs): *convert_args, **convert_kwargs):
super(Lambda, self).convert( super().convert(
value, receiver, context, function_spec, engine, value, receiver, context, function_spec, engine,
*convert_args, **convert_kwargs) *convert_args, **convert_kwargs)
if value is None: if value is None:
@ -301,7 +301,7 @@ class Super(HiddenParameterType, SmartType):
self.with_context = with_context self.with_context = with_context
self.method = method self.method = method
self.with_name = with_name self.with_name = with_name
super(Super, self).__init__(False) super().__init__(False)
@staticmethod @staticmethod
def _find_function_context(spec, context): def _find_function_context(spec, context):
@ -353,7 +353,7 @@ class Context(HiddenParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(Context, self).__init__(False) super().__init__(False)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
@ -365,7 +365,7 @@ class Delegate(HiddenParameterType, SmartType):
def __init__(self, name=None, with_context=False, method=False, def __init__(self, name=None, with_context=False, method=False,
use_convention=True): use_convention=True):
super(Delegate, self).__init__(False) super().__init__(False)
self.name = name self.name = name
self.with_context = with_context self.with_context = with_context
self.method = method self.method = method
@ -403,7 +403,7 @@ class Receiver(HiddenParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(Receiver, self).__init__(False) super().__init__(False)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
@ -414,7 +414,7 @@ class Engine(HiddenParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(Engine, self).__init__(False) super().__init__(False)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
@ -425,7 +425,7 @@ class FunctionDefinition(HiddenParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(FunctionDefinition, self).__init__(False) super().__init__(False)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
@ -437,16 +437,16 @@ class Constant(SmartType):
def __init__(self, nullable, expand=True): def __init__(self, nullable, expand=True):
self.expand = expand self.expand = expand
super(Constant, self).__init__(nullable) super().__init__(nullable)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return super(Constant, self).check( return super().check(
value, context, *args, **kwargs) and ( value, context, *args, **kwargs) and (
value is None or isinstance(value, expressions.Constant)) value is None or isinstance(value, expressions.Constant))
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
super(Constant, self).convert( super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
return value.value if self.expand else value return value.value if self.expand else value
@ -455,7 +455,7 @@ class YaqlExpression(LazyParameterType, SmartType):
__slots__ = ('_expression_types',) __slots__ = ('_expression_types',)
def __init__(self, expression_type=None): def __init__(self, expression_type=None):
super(YaqlExpression, self).__init__(False) super().__init__(False)
if expression_type and not utils.is_sequence(expression_type): if expression_type and not utils.is_sequence(expression_type):
expression_type = (expression_type,) expression_type = (expression_type,)
self._expression_types = expression_type self._expression_types = expression_type
@ -467,7 +467,7 @@ class YaqlExpression(LazyParameterType, SmartType):
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):
super(YaqlExpression, self).convert( super().convert(
value, receiver, context, function_spec, engine, *args, **kwargs) value, receiver, context, function_spec, engine, *args, **kwargs)
return value return value
@ -476,10 +476,10 @@ class StringConstant(Constant):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False): def __init__(self, nullable=False):
super(StringConstant, self).__init__(nullable) super().__init__(nullable)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return super(StringConstant, self).check( return super().check(
value, context, *args, **kwargs) and ( value, context, *args, **kwargs) and (
value is None or isinstance(value.value, str)) value is None or isinstance(value.value, str))
@ -488,7 +488,7 @@ class Keyword(Constant):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, expand=True): def __init__(self, expand=True):
super(Keyword, self).__init__(False, expand) super().__init__(False, expand)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return isinstance(value, expressions.KeywordConstant) return isinstance(value, expressions.KeywordConstant)
@ -498,10 +498,10 @@ class BooleanConstant(Constant):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False, expand=True): def __init__(self, nullable=False, expand=True):
super(BooleanConstant, self).__init__(nullable, expand) super().__init__(nullable, expand)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return super(BooleanConstant, self).check( return super().check(
value, context, *args, **kwargs) and ( value, context, *args, **kwargs) and (
value is None or type(value.value) is bool) value is None or type(value.value) is bool)
@ -510,10 +510,10 @@ class NumericConstant(Constant):
__slots__ = tuple() __slots__ = tuple()
def __init__(self, nullable=False, expand=True): def __init__(self, nullable=False, expand=True):
super(NumericConstant, self).__init__(nullable, expand) super().__init__(nullable, expand)
def check(self, value, context, *args, **kwargs): def check(self, value, context, *args, **kwargs):
return super(NumericConstant, self).check( return super().check(
value, context, *args, **kwargs) and ( value, context, *args, **kwargs) and (
value is None or value is None or
isinstance(value.value, (int, float)) and isinstance(value.value, (int, float)) and
@ -525,7 +525,7 @@ class SmartTypeAggregation(SmartType, metaclass=abc.ABCMeta):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.nullable = kwargs.pop('nullable', False) self.nullable = kwargs.pop('nullable', False)
super(SmartTypeAggregation, self).__init__(self.nullable) super().__init__(self.nullable)
self.types = [] self.types = []
for item in args: for item in args:
@ -625,12 +625,12 @@ class NotOfType(SmartType):
if isinstance(smart_type, (type, tuple)): if isinstance(smart_type, (type, tuple)):
smart_type = PythonType(smart_type, nullable=nullable) smart_type = PythonType(smart_type, nullable=nullable)
self.smart_type = smart_type self.smart_type = smart_type
super(NotOfType, self).__init__(nullable) super().__init__(nullable)
def check(self, value, context, engine, *args, **kwargs): def check(self, value, context, engine, *args, **kwargs):
if isinstance(value, expressions.Constant): if isinstance(value, expressions.Constant):
value = value.value value = value.value
if not super(NotOfType, self).check( if not super().check(
value, context, engine, *args, **kwargs): value, context, engine, *args, **kwargs):
return False return False
if value is None or isinstance(value, expressions.Expression): if value is None or isinstance(value, expressions.Expression):
@ -643,7 +643,7 @@ class YaqlInterface(HiddenParameterType, SmartType):
__slots__ = tuple() __slots__ = tuple()
def __init__(self): def __init__(self):
super(YaqlInterface, self).__init__(False) super().__init__(False)
def convert(self, value, receiver, context, function_spec, engine, def convert(self, value, receiver, context, function_spec, engine,
*args, **kwargs): *args, **kwargs):

View File

@ -20,7 +20,7 @@ from yaql.standard_library import legacy as std_legacy
class YaqlFactory(factory.YaqlFactory): class YaqlFactory(factory.YaqlFactory):
def __init__(self, allow_delegates=False): def __init__(self, allow_delegates=False):
# noinspection PyTypeChecker # noinspection PyTypeChecker
super(YaqlFactory, self).__init__( super().__init__(
keyword_operator=None, allow_delegates=allow_delegates) keyword_operator=None, allow_delegates=allow_delegates)
self.insert_operator( self.insert_operator(
'or', True, '=>', 'or', True, '=>',
@ -30,7 +30,7 @@ class YaqlFactory(factory.YaqlFactory):
options = dict(options or {}) options = dict(options or {})
options['yaql.convertTuplesToLists'] = False options['yaql.convertTuplesToLists'] = False
options['yaql.iterableDicts'] = True options['yaql.iterableDicts'] = True
return super(YaqlFactory, self).create(options) return super().create(options)
def create_context(*args, **kwargs): def create_context(*args, **kwargs):

View File

@ -43,8 +43,7 @@ def list_(delegate, *args):
def rec(seq): def rec(seq):
for t in seq: for t in seq:
if utils.is_iterator(t): if utils.is_iterator(t):
for t2 in rec(t): yield from rec(t)
yield t2
else: else:
yield t yield t
return delegate(rec(args)) return delegate(rec(args))
@ -69,8 +68,7 @@ def flatten(collection):
""" """
for t in collection: for t in collection:
if utils.is_iterable(t): if utils.is_iterable(t):
for t2 in flatten(t): yield from flatten(t)
yield t2
else: else:
yield t yield t
@ -868,8 +866,7 @@ def replace_many(collection, position, values, count=1):
if (count >= 0 and position <= i < position + count if (count >= 0 and position <= i < position + count
or count < 0 and i >= position): or count < 0 and i >= position):
if not yielded: if not yielded:
for v in values: yield from values
yield v
yielded = True yielded = True
else: else:
yield t yield t
@ -1019,17 +1016,14 @@ def insert_many(collection, position, values):
""" """
i = -1 i = -1
if position < 0: if position < 0:
for j in values: yield from values
yield j
for i, t in enumerate(collection): for i, t in enumerate(collection):
if i == position: if i == position:
for j in values: yield from values
yield j
yield t yield t
if position > i: if position > i:
for j in values: yield from values
yield j
@specs.parameter('s', utils.SetType, alias='set') @specs.parameter('s', utils.SetType, alias='set')
@ -1073,8 +1067,7 @@ def set_(delegate, *args):
def rec(seq): def rec(seq):
for t in seq: for t in seq:
if utils.is_iterator(t): if utils.is_iterator(t):
for t2 in rec(t): yield from rec(t)
yield t2
else: else:
yield t yield t
return delegate(rec(args)) return delegate(rec(args))

View File

@ -45,7 +45,7 @@ class OrderingIterable(utils.IterableType):
return iter(self.sorted) return iter(self.sorted)
def do_sort(outer_self): def do_sort(outer_self):
class Comparator(object): class Comparator:
@staticmethod @staticmethod
def compare(left, right): def compare(left, right):
result = 0 result = 0
@ -229,10 +229,8 @@ def append(collection, *args):
yaql> [1, 2, 3].append(4, 5) yaql> [1, 2, 3].append(4, 5)
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
""" """
for t in collection: yield from collection
yield t yield from args
for t in args:
yield t
@specs.parameter('collection', yaqltypes.Iterable()) @specs.parameter('collection', yaqltypes.Iterable())
@ -653,8 +651,7 @@ def select_many(collection, selector):
for item in collection: for item in collection:
inner = selector(item) inner = selector(item)
if utils.is_iterable(inner): if utils.is_iterable(inner):
for t in inner: yield from inner
yield t
else: else:
yield inner yield inner
@ -847,7 +844,7 @@ def then_by_descending(collection, selector, context):
return collection return collection
class GroupAggregator(object): class GroupAggregator:
"""A function to aggregate the members of a group found by group_by(). """A function to aggregate the members of a group found by group_by().
The user-specified function is provided at creation. It is assumed to The user-specified function is provided at creation. It is assumed to
@ -1460,7 +1457,7 @@ def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
if max_levels != 1 and isinstance(value2, utils.MappingType): if max_levels != 1 and isinstance(value2, utils.MappingType):
if not isinstance(value1, utils.MappingType): if not isinstance(value1, utils.MappingType):
raise TypeError( raise TypeError(
'Cannot merge {0} with {1}'.format( 'Cannot merge {} with {}'.format(
type(value1), type(value2))) type(value1), type(value2)))
result[key] = _merge_dicts( result[key] = _merge_dicts(
value1, value2, list_merge_func, item_merger, value1, value2, list_merge_func, item_merger,
@ -1468,7 +1465,7 @@ def _merge_dicts(dict1, dict2, list_merge_func, item_merger, max_levels=0):
elif max_levels != 1 and utils.is_sequence(value2): elif max_levels != 1 and utils.is_sequence(value2):
if not utils.is_sequence(value1): if not utils.is_sequence(value1):
raise TypeError( raise TypeError(
'Cannot merge {0} with {1}'.format( 'Cannot merge {} with {}'.format(
type(value1), type(value2))) type(value1), type(value2)))
result[key] = list_merge_func(value1, value2) result[key] = list_merge_func(value1, value2)
else: else:

View File

@ -584,7 +584,7 @@ def string_by_int(left, right, engine):
yaql> "ab" * 2 yaql> "ab" * 2
"abab" "abab"
""" """
utils.limit_memory_usage(engine, (-right + 1, u''), (right, left)) utils.limit_memory_usage(engine, (-right + 1, ''), (right, left))
return left * right return left * right

View File

@ -120,7 +120,7 @@ def unpack(sequence, context, *args):
""" """
lst = tuple(itertools.islice(sequence, len(args) + 1)) lst = tuple(itertools.islice(sequence, len(args) + 1))
if 0 < len(args) != len(lst): if 0 < len(args) != len(lst):
raise ValueError('Cannot unpack {0} elements into {1}'.format( raise ValueError('Cannot unpack {} elements into {}'.format(
len(lst), len(args))) len(lst), len(args)))
if len(args) > 0: if len(args) > 0:
for i in range(len(lst)): for i in range(len(lst)):
@ -231,7 +231,7 @@ def send_context(left, right):
@specs.method @specs.method
@specs.parameter('condition', yaqltypes.Lambda()) @specs.parameter('condition', yaqltypes.Lambda())
@specs.parameter('message', yaqltypes.String()) @specs.parameter('message', yaqltypes.String())
def assert__(engine, obj, condition, message=u'Assertion failed'): def assert__(engine, obj, condition, message='Assertion failed'):
""":yaql:assert """:yaql:assert
Evaluates condition against object. If it evaluates to true returns the Evaluates condition against object. If it evaluates to true returns the
@ -329,7 +329,7 @@ def get_property(func, obj, name):
yaql> now().year yaql> now().year
2016 2016
""" """
func_name = '#property#{0}'.format(name) func_name = '#property#{}'.format(name)
return func(func_name, obj) return func(func_name, obj)

View File

@ -73,7 +73,7 @@ class Yaqlized(yaqltypes.GenericType):
return False return False
return True return True
super(Yaqlized, self).__init__(checker=check_value, nullable=False) super().__init__(checker=check_value, nullable=False)
def _match_name_to_entry(name, entry): def _match_name_to_entry(name, entry):

View File

@ -84,7 +84,7 @@ class TestCase(testtools.TestCase):
self._engine = None self._engine = None
self._legacy_context = None self._legacy_context = None
self._legacy_engine = None self._legacy_engine = None
super(TestCase, self).setUp() super().setUp()
def eval(self, expression, data=None, context=None): def eval(self, expression, data=None, context=None):
expr = self.engine(expression) expr = self.engine(expression)

View File

@ -18,7 +18,7 @@ import yaql.tests
class TestLegacyNewEngine(yaql.tests.TestCase): class TestLegacyNewEngine(yaql.tests.TestCase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TestLegacyNewEngine, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.eval = self.legacy_eval_new_engine self.eval = self.legacy_eval_new_engine
def test_dict(self): def test_dict(self):
@ -123,7 +123,7 @@ class TestLegacyNewEngine(yaql.tests.TestCase):
class TestLegacy(TestLegacyNewEngine): class TestLegacy(TestLegacyNewEngine):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(TestLegacy, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.eval = self.legacy_eval self.eval = self.legacy_eval
def test_tuples_func(self): def test_tuples_func(self):

View File

@ -368,7 +368,7 @@ class TestQueries(yaql.tests.TestCase):
def test_accumulate(self): def test_accumulate(self):
self.assertEqual( self.assertEqual(
['a', 'aa', u'aab', 'aaba', 'aabaa'], ['a', 'aa', 'aab', 'aaba', 'aabaa'],
self.eval('[a,a,b,a,a].accumulate($1 + $2)')) self.eval('[a,a,b,a,a].accumulate($1 + $2)'))
self.assertEqual( self.assertEqual(

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015 Mirantis, Inc. # Copyright (c) 2015 Mirantis, Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -35,11 +33,11 @@ class TestStrings(yaql.tests.TestCase):
def test_to_upper(self): def test_to_upper(self):
self.assertEqual('QQ', self.eval('qq.toUpper()')) self.assertEqual('QQ', self.eval('qq.toUpper()'))
self.assertEqual(u'ПРИВЕТ', self.eval(u'Привет.toUpper()')) self.assertEqual('ПРИВЕТ', self.eval('Привет.toUpper()'))
def test_to_lower(self): def test_to_lower(self):
self.assertEqual('qq', self.eval('QQ.toLower()')) self.assertEqual('qq', self.eval('QQ.toLower()'))
self.assertEqual(u'привет', self.eval(u'Привет.toLower()')) self.assertEqual('привет', self.eval('Привет.toLower()'))
def test_eq(self): def test_eq(self):
self.assertTrue(self.eval('a = a')) self.assertTrue(self.eval('a = a'))

View File

@ -21,10 +21,10 @@ from yaql import yaqlization
class TestYaqlization(tests.TestCase): class TestYaqlization(tests.TestCase):
def _get_sample_class(self): def _get_sample_class(self):
class D(object): class D:
d_attr = 777 d_attr = 777
class C(object): class C:
def __init__(self): def __init__(self):
self.attr = 123 self.attr = 123
@ -176,14 +176,14 @@ class TestYaqlization(tests.TestCase):
def test_yaqlify_decorator(self): def test_yaqlify_decorator(self):
@yaqlization.yaqlize @yaqlization.yaqlize
class C(object): class C:
attr = 555 attr = 555
self.assertEqual(555, self.eval('$.attr', C())) self.assertEqual(555, self.eval('$.attr', C()))
def test_yaqlify_decorator_with_parameters(self): def test_yaqlify_decorator_with_parameters(self):
@yaqlization.yaqlize(yaqlize_attributes=True) @yaqlization.yaqlize(yaqlize_attributes=True)
class C(object): class C:
attr = 555 attr = 555
self.assertEqual(555, self.eval('$.attr', C())) self.assertEqual(555, self.eval('$.attr', C()))

View File

@ -15,7 +15,7 @@
from yaql.language import utils from yaql.language import utils
class YaqlInterface(object): class YaqlInterface:
def __init__(self, context, engine, receiver=utils.NO_VALUE): def __init__(self, context, engine, receiver=utils.NO_VALUE):
self.__sender = receiver self.__sender = receiver
self.__engine = engine self.__engine = engine