def visit_list(self, node: astroid.List) -> None:
     if node.ctx == astroid.Store:
         # List is the target of an assignment; do not give it a type.
         node.inf_type = NoType()
     elif not node.elts:
         node.inf_type = TypeInfo(List[self.type_constraints.fresh_tvar(node)])
     else:
         elt_inf_type = self._unify_elements(node.elts, node)
         node.inf_type = wrap_container(List, elt_inf_type)
Exemple #2
0
 def visit_list(self, node: astroid.List) -> None:
     if node.ctx == astroid.Store:
         # List is the target of an assignment; do not give it a type.
         node.inf_type = NoType()
     elif not node.elts:
         node.inf_type = TypeInfo(List[self.type_constraints.fresh_tvar(node)])
     else:
         elt_inf_type = self._unify_elements(node.elts, node)
         node.inf_type = wrap_container(List, elt_inf_type)
 def visit_list(self, node: astroid.List) -> None:
     if node.ctx == astroid.Store:
         # List is the target of an assignment; do not give it a type.
         node.inf_type = TypeInfo(NoType)
     elif node.elts == []:
         node.inf_type = TypeInfo(List[Any])
     else:
         node_type = node.elts[0].inf_type.getValue()
         for elt in node.elts:
             if isinstance(node_type, type):
                 node_type = self.type_constraints.unify(
                     elt.inf_type.getValue(), node_type, node).getValue()
         if isinstance(node_type, str):
             node_type = Any
         node.inf_type = TypeInfo(List[node_type])
Exemple #4
0
def _pep8(name, caps=re.compile('([A-Z])')):
    return caps.sub(lambda m: '_' + m.groups()[0].lower(), name)


def nose_transform():
    """Custom transform for the nose.tools module."""

    builder = AstroidBuilder(MANAGER)
    stub = AstroidBuilder(MANAGER).string_build('''__all__ = []''')
    unittest_module = builder.module_build(unittest.case)
    case = unittest_module['TestCase']
    all_entries = ['ok_', 'eq_']

    for method_name, method in case.locals.items():
        if method_name.startswith('assert') and '_' not in method_name:
            pep8_name = _pep8(method_name)
            all_entries.append(pep8_name)
            stub[pep8_name] = method[0]

    # Update the __all__ variable, since nose.tools
    # does this manually with .append.
    all_assign = stub['__all__'].parent
    all_object = List(all_entries)
    all_object.parent = all_assign
    all_assign.value = all_object
    return stub


register_module_extender(MANAGER, 'nose.tools.trivial', nose_transform)