コード例 #1
0
    def matches_signature(self, arguments):
        from jedi.inference.param import get_executed_param_names_and_issues
        executed_param_names, issues = \
            get_executed_param_names_and_issues(self._function_value, arguments)
        if issues:
            return False

        matches = all(executed_param_name.matches_signature()
                      for executed_param_name in executed_param_names)
        if debug.enable_notice:
            tree_node = self._function_value.tree_node
            signature = parser_utils.get_signature(tree_node)
            if matches:
                debug.dbg("Overloading match: %s@%s (%s)",
                          signature,
                          tree_node.start_pos[0],
                          arguments,
                          color='BLUE')
            else:
                debug.dbg("Overloading no match: %s@%s (%s)",
                          signature,
                          tree_node.start_pos[0],
                          arguments,
                          color='BLUE')
        return matches
コード例 #2
0
def test_complex(Script, environment):
    s = """
            def abc(a,b):
                pass

            def a(self):
                abc(

            if 1:
                pass
        """
    assert_signature(Script, s, 'abc', 0, line=6, column=20)
    s = """
            import re
            def huhu(it):
                re.compile(
                return it * 2
        """
    sig1, sig2 = sorted(Script(s).get_signatures(line=4, column=27),
                        key=lambda s: s.line)
    assert sig1.name == sig2.name == 'compile'
    assert sig1.index == sig2.index == 0
    func1, = sig1._name.infer()
    func2, = sig2._name.infer()

    if environment.version_info.major == 3:
        # Do these checks just for Python 3, I'm too lazy to deal with this
        # legacy stuff. ~ dave.
        assert get_signature(func1.tree_node) \
            == 'compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]'
        assert get_signature(func2.tree_node) \
            == 'compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) ->\nPattern[AnyStr]'

    # jedi-vim #70
    s = """def foo("""
    assert Script(s).get_signatures() == []

    # jedi-vim #116
    s = """import itertools; test = getattr(itertools, 'chain'); test("""
    assert_signature(Script, s, 'chain', 0)
コード例 #3
0
def test_get_signature(code, signature):
    node = parse(code, version='3.5').children[0]
    if node.type == 'simple_stmt':
        node = node.children[0]
    assert parser_utils.get_signature(node) == signature