diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-02 09:43:56 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-10-02 09:43:56 +0200 |
commit | add5f7b8eba427de9d39caae864bbc6dc37ef980 (patch) | |
tree | 86bb7df77f389062879365e97df0c3d53d38a8a6 /astroid/util.py | |
parent | bb46cd198b93f3715da94089d42f39fc910892ff (diff) | |
download | astroid-git-add5f7b8eba427de9d39caae864bbc6dc37ef980.tar.gz |
Initial formatting of astroid
Diffstat (limited to 'astroid/util.py')
-rw-r--r-- | astroid/util.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/astroid/util.py b/astroid/util.py index 9fa4d358..cdd705fb 100644 --- a/astroid/util.py +++ b/astroid/util.py @@ -17,27 +17,31 @@ def lazy_descriptor(obj): class DescriptorProxy(lazy_object_proxy.Proxy): def __get__(self, instance, owner=None): return self.__class__.__get__(self, instance) + return DescriptorProxy(obj) def lazy_import(module_name): return lazy_object_proxy.Proxy( - lambda: importlib.import_module('.' + module_name, 'astroid')) + lambda: importlib.import_module("." + module_name, "astroid") + ) @object.__new__ class Uninferable: """Special inference object, which is returned when inference fails.""" + def __repr__(self): - return 'Uninferable' + return "Uninferable" + __str__ = __repr__ def __getattribute__(self, name): - if name == 'next': - raise AttributeError('next method should not be called') - if name.startswith('__') and name.endswith('__'): + if name == "next": + raise AttributeError("next method should not be called") + if name.startswith("__") and name.endswith("__"): return object.__getattribute__(self, name) - if name == 'accept': + if name == "accept": return object.__getattribute__(self, name) return self @@ -53,6 +57,7 @@ class Uninferable: func = getattr(visitor, "visit_uninferable") return func(self) + class BadOperationMessage: """Object which describes a TypeError occurred somewhere in the inference chain @@ -71,7 +76,7 @@ class BadUnaryOperationMessage(BadOperationMessage): @property def _object_type_helper(self): - helpers = lazy_import('helpers') + helpers = lazy_import("helpers") return helpers.object_type def _object_type(self, obj): @@ -83,11 +88,11 @@ class BadUnaryOperationMessage(BadOperationMessage): return objtype def __str__(self): - if hasattr(self.operand, 'name'): + if hasattr(self.operand, "name"): operand_type = self.operand.name else: object_type = self._object_type(self.operand) - if hasattr(object_type, 'name'): + if hasattr(object_type, "name"): operand_type = object_type.name else: # Just fallback to as_string @@ -114,18 +119,25 @@ def _instancecheck(cls, other): wrapped = cls.__wrapped__ other_cls = other.__class__ is_instance_of = wrapped is other_cls or issubclass(other_cls, wrapped) - warnings.warn("%r is deprecated and slated for removal in astroid " - "2.0, use %r instead" % (cls.__class__.__name__, - wrapped.__name__), - PendingDeprecationWarning, stacklevel=2) + warnings.warn( + "%r is deprecated and slated for removal in astroid " + "2.0, use %r instead" % (cls.__class__.__name__, wrapped.__name__), + PendingDeprecationWarning, + stacklevel=2, + ) return is_instance_of def proxy_alias(alias_name, node_type): """Get a Proxy from the given name to the given node type.""" - proxy = type(alias_name, (lazy_object_proxy.Proxy,), - {'__class__': object.__dict__['__class__'], - '__instancecheck__': _instancecheck}) + proxy = type( + alias_name, + (lazy_object_proxy.Proxy,), + { + "__class__": object.__dict__["__class__"], + "__instancecheck__": _instancecheck, + }, + ) return proxy(lambda: node_type) |