1
- # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2
- # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
3
- #
4
- # This file is part of astroid.
5
- #
6
- # astroid is free software: you can redistribute it and/or modify it
7
- # under the terms of the GNU Lesser General Public License as published by the
8
- # Free Software Foundation, either version 2.1 of the License, or (at your
9
- # option) any later version.
10
- #
11
- # astroid is distributed in the hope that it will be useful, but
12
- # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14
- # for more details.
15
- #
16
- # You should have received a copy of the GNU Lesser General Public License along
17
- # with astroid. If not, see <http://www.gnu.org/licenses/>.
1
+ # Copyright (c) 2006-2013, 2015 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
2
+ # Copyright (c) 2014 Google, Inc.
3
+ # Copyright (c) 2015-2016 Claudiu Popa <pcmanticore@gmail.com>
4
+
5
+ # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
6
+ # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
7
+
18
8
"""Python Abstract Syntax Tree New Generation
19
9
20
10
The aim of this module is to provide a common base representation of
39
29
40
30
* builder contains the class responsible to build astroid trees
41
31
"""
42
- __doctype__ = "restructuredtext en"
43
32
33
+ import os
44
34
import sys
45
35
import re
46
36
from operator import attrgetter
47
37
38
+ import enum
39
+
40
+
41
+ _Context = enum .Enum ('Context' , 'Load Store Del' )
42
+ Load = _Context .Load
43
+ Store = _Context .Store
44
+ Del = _Context .Del
45
+ del _Context
46
+
47
+
48
+ from .__pkginfo__ import version as __version__
48
49
# WARNING: internal imports order matters !
49
50
51
+ # pylint: disable=redefined-builtin, wildcard-import
52
+
50
53
# make all exception classes accessible from astroid package
51
54
from astroid .exceptions import *
52
55
58
61
59
62
# more stuff available
60
63
from astroid import raw_building
61
- from astroid .bases import Instance , BoundMethod , UnboundMethod
64
+ from astroid .bases import BaseInstance , Instance , BoundMethod , UnboundMethod
62
65
from astroid .node_classes import are_exclusive , unpack_infer
63
66
from astroid .scoped_nodes import builtin_lookup
64
- from astroid .builder import parse
65
- from astroid .util import YES
67
+ from astroid .builder import parse , extract_node
68
+ from astroid .util import Uninferable , YES
66
69
67
- # make a manager instance (borg) as well as Project and Package classes
68
- # accessible from astroid package
70
+ # make a manager instance (borg) accessible from astroid package
69
71
from astroid .manager import AstroidManager
70
72
MANAGER = AstroidManager ()
71
73
del AstroidManager
72
74
73
75
# transform utilities (filters and decorator)
74
76
75
77
class AsStringRegexpPredicate (object ):
76
- """Class to be used as predicate that may be given to `register_transform`
78
+ """ClassDef to be used as predicate that may be given to `register_transform`
77
79
78
80
First argument is a regular expression that will be searched against the `as_string`
79
81
representation of the node onto which it's applied.
@@ -92,6 +94,7 @@ def __init__(self, regexp, expression=None):
92
94
def __call__ (self , node ):
93
95
if self .expression is not None :
94
96
node = attrgetter (self .expression )(node )
97
+ # pylint: disable=no-member; github.com/pycqa/astroid/126
95
98
return self .regexp .search (node .as_string ())
96
99
97
100
def inference_tip (infer_function ):
@@ -114,8 +117,8 @@ def transform(node, infer_function=infer_function):
114
117
def register_module_extender (manager , module_name , get_extension_mod ):
115
118
def transform (node ):
116
119
extension_module = get_extension_mod ()
117
- for name , objs in extension_module ._locals .items ():
118
- node ._locals [name ] = objs
120
+ for name , objs in extension_module .locals .items ():
121
+ node .locals [name ] = objs
119
122
for obj in objs :
120
123
if obj .parent is extension_module :
121
124
obj .parent = node
@@ -124,13 +127,11 @@ def transform(node):
124
127
125
128
126
129
# load brain plugins
127
- from os import listdir
128
- from os .path import join , dirname
129
- BRAIN_MODULES_DIR = join (dirname (__file__ ), 'brain' )
130
+ BRAIN_MODULES_DIR = os .path .join (os .path .dirname (__file__ ), 'brain' )
130
131
if BRAIN_MODULES_DIR not in sys .path :
131
132
# add it to the end of the list so user path take precedence
132
133
sys .path .append (BRAIN_MODULES_DIR )
133
134
# load modules in this directory
134
- for module in listdir (BRAIN_MODULES_DIR ):
135
+ for module in os . listdir (BRAIN_MODULES_DIR ):
135
136
if module .endswith ('.py' ):
136
137
__import__ (module [:- 3 ])
0 commit comments