diff options
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/bases.py | 14 | ||||
-rw-r--r-- | astroid/const.py | 3 | ||||
-rw-r--r-- | astroid/helpers.py | 3 | ||||
-rw-r--r-- | astroid/nodes/node_classes.py | 12 | ||||
-rw-r--r-- | astroid/nodes/scoped_nodes.py | 28 | ||||
-rw-r--r-- | astroid/objects.py | 7 |
6 files changed, 31 insertions, 36 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index 19c5039e..56f851f9 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -29,7 +29,7 @@ import collections from astroid import context as contextmod from astroid import decorators, util -from astroid.const import BUILTINS, PY310_PLUS +from astroid.const import PY310_PLUS from astroid.exceptions import ( AstroidTypeError, AttributeInferenceError, @@ -45,7 +45,7 @@ manager = util.lazy_import("manager") # TODO: check if needs special treatment BOOL_SPECIAL_METHOD = "__bool__" -PROPERTIES = {BUILTINS + ".property", "abc.abstractproperty"} +PROPERTIES = {"builtins.property", "abc.abstractproperty"} if PY310_PLUS: PROPERTIES.add("enum.property") @@ -94,7 +94,7 @@ def _is_property(meth, context=None): if base_class.__class__.__name__ != "Name": continue module, _ = base_class.lookup(base_class.name) - if module.name == BUILTINS and base_class.name == "property": + if module.name == "builtins" and base_class.name == "property": return True return False @@ -394,7 +394,7 @@ class UnboundMethod(Proxy): # instance of the class given as first argument. if ( self._proxied.name == "__new__" - and self._proxied.parent.frame().qname() == "%s.object" % BUILTINS + and self._proxied.parent.frame().qname() == "builtins.object" ): if caller.args: node_context = context.extra_context.get(caller.args[0]) @@ -445,7 +445,7 @@ class BoundMethod(UnboundMethod): if mcs.__class__.__name__ != "ClassDef": # Not a valid first argument. return None - if not mcs.is_subtype_of("%s.type" % BUILTINS): + if not mcs.is_subtype_of("builtins.type"): # Not a valid metaclass. return None @@ -558,7 +558,7 @@ class Generator(BaseInstance): return False def pytype(self): - return "%s.generator" % BUILTINS + return "builtins.generator" def display_type(self): return "Generator" @@ -579,7 +579,7 @@ class AsyncGenerator(Generator): """Special node representing an async generator""" def pytype(self): - return "%s.async_generator" % BUILTINS + return "builtins.async_generator" def display_type(self): return "AsyncGenerator" diff --git a/astroid/const.py b/astroid/const.py index f3c4ee7d..b00dee7a 100644 --- a/astroid/const.py +++ b/astroid/const.py @@ -1,4 +1,3 @@ -import builtins import enum import sys @@ -18,5 +17,3 @@ class Context(enum.Enum): Load = Context.Load Store = Context.Store Del = Context.Del - -BUILTINS = builtins.__name__ # Could be just 'builtins' ? diff --git a/astroid/helpers.py b/astroid/helpers.py index e6ae3abf..f0fbedb6 100644 --- a/astroid/helpers.py +++ b/astroid/helpers.py @@ -21,7 +21,6 @@ Various helper utilities. from astroid import bases from astroid import context as contextmod from astroid import manager, nodes, raw_building, util -from astroid.const import BUILTINS from astroid.exceptions import ( AstroidTypeError, AttributeInferenceError, @@ -40,7 +39,7 @@ def _build_proxy_class(cls_name, builtins): def _function_type(function, builtins): if isinstance(function, scoped_nodes.Lambda): - if function.root().name == BUILTINS: + if function.root().name == "builtins": cls_name = "builtin_function_or_method" else: cls_name = "function" diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 1523707a..53bb62e1 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -45,7 +45,7 @@ from typing import Callable, Generator, Optional from astroid import bases from astroid import context as contextmod from astroid import decorators, mixins, util -from astroid.const import BUILTINS, Context +from astroid.const import Context from astroid.exceptions import ( AstroidIndexError, AstroidTypeError, @@ -2191,7 +2191,7 @@ class Dict(NodeNG, bases.Instance): :returns: The name of the type. :rtype: str """ - return "%s.dict" % BUILTINS + return "builtins.dict" def get_children(self): """Get the key and value nodes below this node. @@ -3083,7 +3083,7 @@ class List(BaseContainer): :returns: The name of the type. :rtype: str """ - return "%s.list" % BUILTINS + return "builtins.list" def getitem(self, index, context=None): """Get an item from this node. @@ -3278,7 +3278,7 @@ class Set(BaseContainer): :returns: The name of the type. :rtype: str """ - return "%s.set" % BUILTINS + return "builtins.set" class Slice(NodeNG): @@ -3356,7 +3356,7 @@ class Slice(NodeNG): :returns: The name of the type. :rtype: str """ - return "%s.slice" % BUILTINS + return "builtins.slice" def igetattr(self, attrname, context=None): """Infer the possible values of the given attribute on the slice. @@ -3710,7 +3710,7 @@ class Tuple(BaseContainer): :returns: The name of the type. :rtype: str """ - return "%s.tuple" % BUILTINS + return "builtins.tuple" def getitem(self, index, context=None): """Get an item from this node. diff --git a/astroid/nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes.py index 5ce6b39c..40eac1c5 100644 --- a/astroid/nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes.py @@ -49,7 +49,7 @@ from astroid import bases from astroid import context as contextmod from astroid import decorators as decorators_mod from astroid import mixins, util -from astroid.const import BUILTINS, PY39_PLUS +from astroid.const import PY39_PLUS from astroid.exceptions import ( AstroidBuildingError, AstroidTypeError, @@ -575,7 +575,7 @@ class Module(LocalsDictNodeNG): :returns: The name of the type. :rtype: str """ - return "%s.module" % BUILTINS + return "builtins.module" def display_type(self): """A human readable type of this node. @@ -1137,9 +1137,9 @@ def _infer_decorator_callchain(node): if isinstance(result, bases.Instance): result = result._proxied if isinstance(result, ClassDef): - if result.is_subtype_of("%s.classmethod" % BUILTINS): + if result.is_subtype_of("builtins.classmethod"): return "classmethod" - if result.is_subtype_of("%s.staticmethod" % BUILTINS): + if result.is_subtype_of("builtins.staticmethod"): return "staticmethod" if isinstance(result, FunctionDef): if not result.decorators: @@ -1152,7 +1152,7 @@ def _infer_decorator_callchain(node): if ( isinstance(decorator, node_classes.Attribute) and isinstance(decorator.expr, node_classes.Name) - and decorator.expr.name == BUILTINS + and decorator.expr.name == "builtins" and decorator.attrname in BUILTIN_DESCRIPTORS ): return decorator.attrname @@ -1241,8 +1241,8 @@ class Lambda(mixins.FilterStmtsMixin, LocalsDictNodeNG): :rtype: str """ if "method" in self.type: - return "%s.instancemethod" % BUILTINS - return "%s.function" % BUILTINS + return "builtins.instancemethod" + return "builtins.function" def display_type(self): """A human readable type of this node. @@ -1541,7 +1541,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): if ( isinstance(node, node_classes.Attribute) and isinstance(node.expr, node_classes.Name) - and node.expr.name == BUILTINS + and node.expr.name == "builtins" and node.attrname in BUILTIN_DESCRIPTORS ): return node.attrname @@ -1571,9 +1571,9 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda): for ancestor in inferred.ancestors(): if not isinstance(ancestor, ClassDef): continue - if ancestor.is_subtype_of("%s.classmethod" % BUILTINS): + if ancestor.is_subtype_of("builtins.classmethod"): return "classmethod" - if ancestor.is_subtype_of("%s.staticmethod" % BUILTINS): + if ancestor.is_subtype_of("builtins.staticmethod"): return "staticmethod" except InferenceError: pass @@ -2162,8 +2162,8 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement :rtype: str """ if self.newstyle: - return "%s.type" % BUILTINS - return "%s.classobj" % BUILTINS + return "builtins.type" + return "builtins.classobj" def display_type(self): """A human readable type of this node. @@ -2250,7 +2250,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement def infer_call_result(self, caller, context=None): """infer what a class is returning when called""" - if self.is_subtype_of(f"{BUILTINS}.type", context) and len(caller.args) == 3: + if self.is_subtype_of("builtins.type", context) and len(caller.args) == 3: result = self._infer_type_call(caller, context) yield result return @@ -2666,7 +2666,7 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG, node_classes.Statement def _valid_getattr(node): root = node.root() - return root.name != BUILTINS and getattr(root, "pure_python", None) + return root.name != "builtins" and getattr(root, "pure_python", None) try: return _valid_getattr(self.getattr("__getattr__", context)[0]) diff --git a/astroid/objects.py b/astroid/objects.py index b26a5dd5..4241c170 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -23,7 +23,6 @@ leads to an inferred FrozenSet: from astroid import bases, decorators, util -from astroid.const import BUILTINS from astroid.exceptions import ( AttributeInferenceError, InferenceError, @@ -40,7 +39,7 @@ class FrozenSet(node_classes.BaseContainer): """class representing a FrozenSet composite node""" def pytype(self): - return "%s.frozenset" % BUILTINS + return "builtins.frozenset" def _infer(self, context=None): yield self @@ -120,7 +119,7 @@ class Super(node_classes.NodeNG): return ast_builtins.getattr("super")[0] def pytype(self): - return "%s.super" % BUILTINS + return "builtins.super" def display_type(self): return "Super of" @@ -307,7 +306,7 @@ class Property(scoped_nodes.FunctionDef): type = "property" def pytype(self): - return "%s.property" % BUILTINS + return "builtins.property" def infer_call_result(self, caller=None, context=None): raise InferenceError("Properties are not callable") |