diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-12-04 12:47:25 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2014-12-04 12:47:25 +0100 |
commit | 2dca16decfd71f490747743f70b7750a8e8cdb0e (patch) | |
tree | b61f7e5ac5792b717bf080931718c6e733bb7828 | |
parent | c44ff12f160aba5a6a0d3c5117c56f31c7996cfd (diff) | |
download | astroid-2dca16decfd71f490747743f70b7750a8e8cdb0e.tar.gz |
don't commit/push without checking for unsaved buffer
-rw-r--r-- | astroid/brain/builtin_inference.py | 7 | ||||
-rw-r--r-- | astroid/brain/py2stdlib.py | 43 |
2 files changed, 6 insertions, 44 deletions
diff --git a/astroid/brain/builtin_inference.py b/astroid/brain/builtin_inference.py index 52eb7bc..fcf8a48 100644 --- a/astroid/brain/builtin_inference.py +++ b/astroid/brain/builtin_inference.py @@ -1,10 +1,15 @@ """Astroid hooks for various builtins.""" + +import sys from functools import partial +from textwrap import dedent import six from astroid import (MANAGER, UseInferenceDefault, inference_tip, YES, InferenceError, UnresolvableName) from astroid import nodes +from astroid.builder import AstroidBuilder + def _extend_str(class_node, rvalue): """function to extend builtin str/unicode class""" @@ -42,7 +47,7 @@ def extend_builtins(class_transforms): for class_name, transform in class_transforms.items(): transform(builtin_ast[class_name]) -if PY3K: +if sys.version_info > (3, 0): extend_builtins({'bytes': partial(_extend_str, rvalue="b''"), 'str': partial(_extend_str, rvalue="''")}) else: diff --git a/astroid/brain/py2stdlib.py b/astroid/brain/py2stdlib.py index f4f4a92..b79eb6f 100644 --- a/astroid/brain/py2stdlib.py +++ b/astroid/brain/py2stdlib.py @@ -327,47 +327,4 @@ register_module_extender(MANAGER, 'collections', collections_transform) register_module_extender(MANAGER, 'pkg_resourcds', pkg_resources_transform) register_module_extender(MANAGER, 'subprocess', subprocess_transform) -def _extend_str(class_node, rvalue): - """function to extend builtin str/unicode class""" - code = dedent(''' - class whatever(object): - def join(self, iterable): - return {rvalue} - def replace(self, old, new, count=None): - return {rvalue} - def format(self, *args, **kwargs): - return {rvalue} - def encode(self, encoding='ascii', errors=None): - return '' - def decode(self, encoding='ascii', errors=None): - return u'' - ''') - int_meth_str = ' def %s(self, sub, start=None, end=None): return 0' - int_methods = [int_meth_str % meth for meth in ('index', 'find', 'count')] - code += '\n' + '\n'.join(int_methods) - str_meth_str = " def %s(self): return {rvalue} " - str_methods = [str_meth_str % meth for meth in ('capitalize', 'title', 'lower', 'upper', 'swapcase', - 'strip', 'rstrip', 'lstrip', - 'rjust', 'ljust', 'center')] - code += '\n' + '\n'.join(str_methods) - code += '\n' - code = code.format(rvalue=rvalue) - fake = AstroidBuilder(MANAGER).string_build(code)['whatever'] - for method in fake.mymethods(): - class_node.locals[method.name] = [method] - method.parent = class_node - -def extend_builtins(class_transforms): - from astroid.bases import BUILTINS - builtin_ast = MANAGER.astroid_cache[BUILTINS] - for class_name, transform in class_transforms.items(): - transform(builtin_ast[class_name]) - -if PY3K: - extend_builtins({'bytes': partial(_extend_str, rvalue="b''"), - 'str': partial(_extend_str, rvalue="''")}) -else: - extend_builtins({'str': partial(_extend_str, rvalue="''"), - 'unicode': partial(_extend_str, rvalue="u''")}) - |