Ejemplo n.º 1
0
 def wrapper(cls, metaclasses):
     for metaclass in metaclasses:
         if metaclass.py__name__() == 'EnumMeta' \
                 and metaclass.get_root_context().py__name__() == 'enum':
             filter_ = ParserTreeFilter(parent_context=cls.as_context())
             return [DictFilter({
                 name.string_name: EnumInstance(cls, name).name for name in filter_.values()
             })]
     return func(cls, metaclasses)
Ejemplo n.º 2
0
def _add_names_in_same_context(context, string_name):
    if context.tree_node is None:
        return

    until_position = None
    while True:
        filter_ = ParserTreeFilter(
            parent_context=context,
            until_position=until_position,
        )
        names = set(filter_.get(string_name))
        if not names:
            break
        yield from names
        ordered = sorted(names, key=lambda x: x.start_pos)
        until_position = ordered[0].start_pos
Ejemplo n.º 3
0
 def get_filters(self, until_position=None, origin_scope=None):
     yield ParserTreeFilter(
         self.inference_state,
         parent_context=self,
         until_position=until_position,
         origin_scope=origin_scope
     )
Ejemplo n.º 4
0
 def get_filters(self, origin_scope=None):
     yield MergedFilter(
         ParserTreeFilter(parent_context=self.as_context(),
                          origin_scope=origin_scope),
         GlobalNameFilter(self.as_context(), self.tree_node),
     )
     yield DictFilter(self.sub_modules_dict())
     yield DictFilter(self._module_attributes_dict())
     yield from self.iter_star_filters()
Ejemplo n.º 5
0
 def get_filters(self, until_position=None, origin_scope=None):
     filters = self._value.get_filters(origin_scope)
     # Skip the first filter and replace it.
     next(filters, None)
     yield MergedFilter(
         ParserTreeFilter(parent_context=self,
                          until_position=until_position,
                          origin_scope=origin_scope),
         self.get_global_filter(),
     )
     yield from filters
Ejemplo n.º 6
0
def _find_overload_functions(context, tree_node):
    def _is_overload_decorated(funcdef):
        if funcdef.parent.type == 'decorated':
            decorators = funcdef.parent.children[0]
            if decorators.type == 'decorator':
                decorators = [decorators]
            else:
                decorators = decorators.children
            for decorator in decorators:
                dotted_name = decorator.children[1]
                if dotted_name.type == 'name' and dotted_name.value == 'overload':
                    # TODO check with values if it's the right overload
                    return True
        return False

    if tree_node.type == 'lambdef':
        return

    if _is_overload_decorated(tree_node):
        yield tree_node

    while True:
        filter = ParserTreeFilter(
            context,
            until_position=tree_node.start_pos
        )
        names = filter.get(tree_node.name.value)
        assert isinstance(names, list)
        if not names:
            break

        found = False
        for name in names:
            funcdef = name.tree_name.parent
            if funcdef.type == 'funcdef' and _is_overload_decorated(funcdef):
                tree_node = funcdef
                found = True
                yield funcdef

        if not found:
            break
Ejemplo n.º 7
0
 def get_filters(self, until_position=None, origin_scope=None):
     filters = self._value.get_filters(origin_scope)
     # Skip the first filter and replace it.
     next(filters)
     yield MergedFilter(
         ParserTreeFilter(parent_context=self,
                          until_position=until_position,
                          origin_scope=origin_scope),
         GlobalNameFilter(self, self.tree_node),
     )
     for f in filters:  # Python 2...
         yield f
Ejemplo n.º 8
0
 def get_filters(self, until_position=None, origin_scope=None):
     yield ParserTreeFilter(self)
Ejemplo n.º 9
0
 def get_global_filter(self, until_position=None, origin_scope=None):
     return ParserTreeFilter(parent_context=self,
                             until_position=until_position,
                             origin_scope=origin_scope)
Ejemplo n.º 10
0
def _new_dict_filter(cls):
    filter_ = ParserTreeFilter(parent_context=cls.as_context())
    return DictFilter({
        name.string_name: DjangoModelName(cls, name)
        for name in filter_.values()
    })