diff options
| author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-08-19 23:29:07 +0200 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-08-30 18:27:45 +0200 |
| commit | b7fe6a391fa6852825f24a3dbeb8c87904a4a86d (patch) | |
| tree | 0b325981030ea4b276c2b6a6eab2b54b1e55dd88 /astroid | |
| parent | 74e2d1e7fd3ad04e0b3a6df44f6f3141e0a94c2b (diff) | |
| download | astroid-git-b7fe6a391fa6852825f24a3dbeb8c87904a4a86d.tar.gz | |
Do not import entire module in astroid/arguments.py
Diffstat (limited to 'astroid')
| -rw-r--r-- | astroid/arguments.py | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/astroid/arguments.py b/astroid/arguments.py index a1104e2b..0e22a1a6 100644 --- a/astroid/arguments.py +++ b/astroid/arguments.py @@ -9,13 +9,14 @@ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html # For details: https://github.com/PyCQA/astroid/blob/main/LICENSE +from typing import Optional - -from astroid import bases -from astroid import context as contextmod -from astroid import nodes, util -from astroid.context import CallContext +from astroid import nodes +from astroid.bases import Instance +from astroid.const import Context +from astroid.context import CallContext, InferenceContext from astroid.exceptions import InferenceError, NoDefault +from astroid.util import Uninferable class CallSite: @@ -48,26 +49,24 @@ class CallSite: self._unpacked_kwargs = self._unpack_keywords(keywords, context=context) self.positional_arguments = [ - arg for arg in self._unpacked_args if arg is not util.Uninferable + arg for arg in self._unpacked_args if arg is not Uninferable ] self.keyword_arguments = { key: value for key, value in self._unpacked_kwargs.items() - if value is not util.Uninferable + if value is not Uninferable } @classmethod - def from_call(cls, call_node, context=None): + def from_call(cls, call_node, context: Optional[Context] = None): """Get a CallSite object from the given Call node. - :param context: - An instance of :class:`astroid.context.Context` that will be used - to force a single inference path. + context will be used to force a single inference path. """ # Determine the callcontext from the given `context` object if any. - context = context or contextmod.InferenceContext() - callcontext = contextmod.CallContext(call_node.args, call_node.keywords) + context = context or InferenceContext() + callcontext = CallContext(call_node.args, call_node.keywords) return cls(callcontext, context=context) def has_invalid_arguments(self): @@ -92,7 +91,7 @@ class CallSite: def _unpack_keywords(self, keywords, context=None): values = {} - context = context or contextmod.InferenceContext() + context = context or InferenceContext() context.extra_context = self.argument_context_map for name, value in keywords: if name is None: @@ -100,33 +99,33 @@ class CallSite: try: inferred = next(value.infer(context=context)) except InferenceError: - values[name] = util.Uninferable + values[name] = Uninferable continue except StopIteration: continue if not isinstance(inferred, nodes.Dict): # Not something we can work with. - values[name] = util.Uninferable + values[name] = Uninferable continue for dict_key, dict_value in inferred.items: try: dict_key = next(dict_key.infer(context=context)) except InferenceError: - values[name] = util.Uninferable + values[name] = Uninferable continue except StopIteration: continue if not isinstance(dict_key, nodes.Const): - values[name] = util.Uninferable + values[name] = Uninferable continue if not isinstance(dict_key.value, str): - values[name] = util.Uninferable + values[name] = Uninferable continue if dict_key.value in values: # The name is already in the dictionary - values[dict_key.value] = util.Uninferable + values[dict_key.value] = Uninferable self.duplicated_keywords.add(dict_key.value) continue values[dict_key.value] = dict_value @@ -136,23 +135,23 @@ class CallSite: def _unpack_args(self, args, context=None): values = [] - context = context or contextmod.InferenceContext() + context = context or InferenceContext() context.extra_context = self.argument_context_map for arg in args: if isinstance(arg, nodes.Starred): try: inferred = next(arg.value.infer(context=context)) except InferenceError: - values.append(util.Uninferable) + values.append(Uninferable) continue except StopIteration: continue - if inferred is util.Uninferable: - values.append(util.Uninferable) + if inferred is Uninferable: + values.append(Uninferable) continue if not hasattr(inferred, "elts"): - values.append(util.Uninferable) + values.append(Uninferable) continue values.extend(inferred.elts) else: @@ -238,7 +237,7 @@ class CallSite: return iter((boundnode,)) if funcnode.type == "method": - if not isinstance(boundnode, bases.Instance): + if not isinstance(boundnode, Instance): boundnode = boundnode.instantiate_class() return iter((boundnode,)) if funcnode.type == "classmethod": |
