1 from inspect
import Parameter
3 from jedi
.cache
import memoize_method
5 from jedi
import parser_utils
13 for n
in self
.get_param_names(resolve_stars
=True):
15 is_positional |
= kind
== Parameter
.POSITIONAL_ONLY
16 if is_positional
and kind
!= Parameter
.POSITIONAL_ONLY
:
20 if kind
== Parameter
.VAR_POSITIONAL
:
22 elif kind
== Parameter
.KEYWORD_ONLY
and not is_kw_only
:
31 s
= self
.name
.string_name
+ '(' + ', '.join(param_strings()) + ')'
32 annotation
= self
.annotation_string
34 s
+= ' -> ' + annotation
38 class AbstractSignature(_SignatureMixin
):
39 def __init__(self
, value
, is_bound
=False):
41 self
.is_bound
= is_bound
45 return self
.value
.name
48 def annotation_string(self
):
51 def get_param_names(self
, resolve_stars
=False):
52 param_names
= self
._function
_value
.get_param_names()
54 return param_names
[1:]
57 def bind(self
, value
):
58 raise NotImplementedError
60 def matches_signature(self
, arguments
):
64 if self
.value
is self
._function
_value
:
65 return '<%s: %s>' % (self
.__class
__.__name
__, self
.value
)
66 return '<%s: %s, %s>' % (self
.__class
__.__name
__, self
.value
, self
._function
_value
)
69 class TreeSignature(AbstractSignature
):
70 def __init__(self
, value
, function_value
=None, is_bound
=False):
71 super().__init
__(value
, is_bound
)
72 self
._function
_value
= function_value
or value
74 def bind(self
, value
):
75 return TreeSignature(value
, self
._function
_value
, is_bound
=True)
78 def _annotation(self
):
79 # Classes don't need annotations, even if __init__ has one. They always
81 if self
.value
.is_class():
83 return self
._function
_value
.tree_node
.annotation
86 def annotation_string(self
):
90 return a
.get_code(include_prefix
=False)
93 def get_param_names(self
, resolve_stars
=False):
94 params
= self
._function
_value
.get_param_names()
96 from jedi
.inference
.star_args
import process_params
97 params
= process_params(params
)
102 def matches_signature(self
, arguments
):
103 from jedi
.inference
.param
import get_executed_param_names_and_issues
104 executed_param_names
, issues
= \
105 get_executed_param_names_and_issues(self
._function
_value
, arguments
)
109 matches
= all(executed_param_name
.matches_signature()
110 for executed_param_name
in executed_param_names
)
111 if debug
.enable_notice
:
112 tree_node
= self
._function
_value
.tree_node
113 signature
= parser_utils
.get_signature(tree_node
)
115 debug
.dbg("Overloading match: %s@%s (%s)",
116 signature
, tree_node
.start_pos
[0], arguments
, color
='BLUE')
118 debug
.dbg("Overloading no match: %s@%s (%s)",
119 signature
, tree_node
.start_pos
[0], arguments
, color
='BLUE')
123 class BuiltinSignature(AbstractSignature
):
124 def __init__(self
, value
, return_string
, function_value
=None, is_bound
=False):
125 super().__init
__(value
, is_bound
)
126 self
._return
_string
= return_string
127 self
.__function
_value
= function_value
130 def annotation_string(self
):
131 return self
._return
_string
134 def _function_value(self
):
135 if self
.__function
_value
is None:
137 return self
.__function
_value
139 def bind(self
, value
):
140 return BuiltinSignature(
141 value
, self
._return
_string
,
142 function_value
=self
.value
,
147 class SignatureWrapper(_SignatureMixin
):
148 def __init__(self
, wrapped_signature
):
149 self
._wrapped
_signature
= wrapped_signature
151 def __getattr__(self
, name
):
152 return getattr(self
._wrapped
_signature
, name
)