forked from VimPlug/jedi
Evaluate annotations for dataclasses when infer is called on param
This commit is contained in:
@@ -580,7 +580,10 @@ class DataclassParamName(BaseTreeParamName):
|
|||||||
return self._default_node
|
return self._default_node
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
|
if self._annotation_node is None:
|
||||||
return NO_CONTEXTS # TODO implement
|
return NO_CONTEXTS # TODO implement
|
||||||
|
else:
|
||||||
|
return self.parent_context.eval_node(self._annotation_node)
|
||||||
|
|
||||||
|
|
||||||
class ItemGetterCallable(ContextWrapper):
|
class ItemGetterCallable(ContextWrapper):
|
||||||
|
|||||||
@@ -86,12 +86,16 @@ def test_dataclass_signature(Script, skip_pre_python37, start, start_params):
|
|||||||
code = dedent('''
|
code = dedent('''
|
||||||
name: str
|
name: str
|
||||||
foo = 3
|
foo = 3
|
||||||
unit_price: float
|
price: float
|
||||||
quantity_on_hand: int = 0
|
quantity: int = 0.0
|
||||||
|
|
||||||
X(''')
|
X(''')
|
||||||
|
|
||||||
code = 'from dataclasses import dataclass\n' + start + code
|
code = 'from dataclasses import dataclass\n' + start + code
|
||||||
|
|
||||||
sig, = Script(code).call_signatures()
|
sig, = Script(code).call_signatures()
|
||||||
assert [p.name for p in sig.params] == start_params + ['name', 'unit_price', 'quantity_on_hand']
|
assert [p.name for p in sig.params] == start_params + ['name', 'price', 'quantity']
|
||||||
|
quantity, = sig.params[-1].infer()
|
||||||
|
assert quantity.name == 'int'
|
||||||
|
price, = sig.params[-2].infer()
|
||||||
|
assert price.name == 'float'
|
||||||
|
|||||||
Reference in New Issue
Block a user