Merge remote-tracking branch 'origin/master' into typeshed

This commit is contained in:
Dave Halter
2018-12-15 18:20:51 +01:00
6 changed files with 46 additions and 1 deletions

View File

@@ -294,6 +294,11 @@ class DictComprehension(_DictMixin, ComprehensionMixin, Sequence):
def get_mapping_item_contexts(self): def get_mapping_item_contexts(self):
return self._dict_keys(), self._dict_values() return self._dict_keys(), self._dict_values()
def exact_key_items(self):
# NOTE: A smarter thing can probably done here to achieve better
# completions, but at least like this jedi doesn't crash
return []
class GeneratorComprehension(ComprehensionMixin, GeneratorBase): class GeneratorComprehension(ComprehensionMixin, GeneratorBase):
pass pass

View File

@@ -1,3 +1,4 @@
import re
import textwrap import textwrap
from inspect import cleandoc from inspect import cleandoc
@@ -158,6 +159,7 @@ def get_call_signature(funcdef, width=72, call_string=None):
p = '(' + ''.join(param.get_code() for param in funcdef.get_params()).strip() + ')' p = '(' + ''.join(param.get_code() for param in funcdef.get_params()).strip() + ')'
else: else:
p = funcdef.children[2].get_code() p = funcdef.children[2].get_code()
p = re.sub(r'\s+', ' ', p)
if funcdef.annotation: if funcdef.annotation:
rtype = " ->" + funcdef.annotation.get_code() rtype = " ->" + funcdef.annotation.get_code()
else: else:
@@ -187,6 +189,8 @@ def get_doc_with_call_signature(scope_node):
doc = clean_scope_docstring(scope_node) doc = clean_scope_docstring(scope_node)
if call_signature is None: if call_signature is None:
return doc return doc
if not doc:
return call_signature
return '%s\n\n%s' % (call_signature, doc) return '%s\n\n%s' % (call_signature, doc)

View File

@@ -319,6 +319,7 @@ exe['c']
a = 'a' a = 'a'
exe2 = kwargs_func(**{a:3, exe2 = kwargs_func(**{a:3,
'b':4.0}) 'b':4.0})
#? int() #? int()
exe2['a'] exe2['a']
#? float() #? float()
@@ -326,6 +327,19 @@ exe2['b']
#? int() float() #? int() float()
exe2['c'] exe2['c']
exe3 = kwargs_func(**{k: v for k, v in [(a, 3), ('b', 4.0)]})
# Should resolve to the same as 2 but jedi is not smart enough yet
# Here to make sure it doesn't result in crash though
#?
exe3['a']
#?
exe3['b']
#?
exe3['c']
# ----------------- # -----------------
# *args / ** kwargs # *args / ** kwargs
# ----------------- # -----------------

View File

@@ -138,18 +138,30 @@ set_t2.c
# python >= 3.5 # python >= 3.5
d = {'a': 3} d = {'a': 3}
dc = {v: 3 for v in ['a']}
#? dict() #? dict()
{**d} {**d}
#? dict()
{**dc}
#? str() #? str()
{**d, "b": "b"}["b"] {**d, "b": "b"}["b"]
#? str()
{**dc, "b": "b"}["b"]
# Should resolve to int() but jedi is not smart enough yet # Should resolve to int() but jedi is not smart enough yet
# Here to make sure it doesn't result in crash though # Here to make sure it doesn't result in crash though
#? #?
{**d}["a"] {**d}["a"]
# Should resolve to int() but jedi is not smart enough yet
# Here to make sure it doesn't result in crash though
#?
{**dc}["a"]
s = {1, 2, 3} s = {1, 2, 3}
#? set() #? set()

View File

@@ -142,6 +142,16 @@ def test_docstring_keyword(Script):
assert 'assert' in completions[0].docstring() assert 'assert' in completions[0].docstring()
def test_docstring_params_formatting(Script):
defs = Script("""
def func(param1,
param2,
param3):
pass
func""").goto_definitions()
assert defs[0].docstring() == 'func(param1, param2, param3)'
# ---- Numpy Style Tests --- # ---- Numpy Style Tests ---
@pytest.mark.skipif(numpydoc_unavailable, @pytest.mark.skipif(numpydoc_unavailable,

View File

@@ -85,4 +85,4 @@ def test_get_call_signature(code, call_signature):
node = node.children[0] node = node.children[0]
assert parser_utils.get_call_signature(node) == call_signature assert parser_utils.get_call_signature(node) == call_signature
assert parser_utils.get_doc_with_call_signature(node) == (call_signature + '\n\n') assert parser_utils.get_doc_with_call_signature(node) == call_signature