Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Change log for the astroid package (used to be astng)
=====================================================

* Enhancement of brain_numpy by adding different types from
numpy.core.numerictypes

2018-01-23 -- 1.6.1

* Fix a crash when __annotations__ access a parent's __init__ that does not have arguments
Expand Down Expand Up @@ -1384,6 +1387,3 @@ Change log for the astroid package (used to be astng)
longer be maintained (this explains that this package is starting with
the 0.13 version number, since the fork occurs with the version
released in logilab-common 0.12).



33 changes: 33 additions & 0 deletions astroid/brain/brain_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,39 @@ def subtract(x1, x2, {opt_args:s}): pass
def true_divide(x1, x2, {opt_args:s}): pass
'''.format(opt_args=ufunc_optional_keyword_arguments))


def numpy_core_numerictypes_transform():
return astroid.parse('''
# different types defined in numerictypes.py
uint16 = type('uint16')
uint32 = type('uint32')
uint64 = type('uint64')
int128 = type('int128')
uint128 = type('uint128')
float16 = type('float16')
float32 = type('float32')
float64 = type('float64')
float80 = type('float80')
float96 = type('float96')
float128 = type('float128')
float256 = type('float256')
complex32 = type('complex32')
complex64 = type('complex64')
complex128 = type('complex128')
complex160 = type('complex160')
complex192 = type('complex192')
complex256 = type('complex256')
complex512 = type('complex512')
timedelta64 = type('timedelta64')
datetime64 = type('datetime64')
unicode_ = type('unicode_')
string_ = type('string_')
object_ = type('object_')
''')


astroid.register_module_extender(astroid.MANAGER, 'numpy.core.umath', numpy_core_umath_transform)
astroid.register_module_extender(astroid.MANAGER, 'numpy.random.mtrand',
numpy_random_mtrand_transform)
astroid.register_module_extender(astroid.MANAGER, 'numpy.core.numerictypes',
numpy_core_numerictypes_transform)
1 change: 0 additions & 1 deletion astroid/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def cache_generator(self, key, generator):
yield result

self.inferred[key] = tuple(results)
return

@contextlib.contextmanager
def restore_path(self):
Expand Down
2 changes: 1 addition & 1 deletion astroid/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def nodes_of_class(self, klass, skip_klass=None):
for matching in child_node.nodes_of_class(klass, skip_klass):
yield matching

def _infer_name(self, frame, name):
def _infer_name(self, frame, name): #pylint: disable=useless-return
# overridden for ImportFrom, Import, Global, TryExcept and Arguments
return None

Expand Down
4 changes: 2 additions & 2 deletions astroid/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,15 +536,15 @@ def statement(self):
"""
return self

def previous_sibling(self):
def previous_sibling(self): #pylint: disable=useless-return
"""The previous sibling statement.

:returns: The previous sibling statement node.
:rtype: NodeNG or None
"""
return

def next_sibling(self):
def next_sibling(self): #pylint: disable=useless-return
"""The next sibling statement node.

:returns: The next sibling statement node.
Expand Down
27 changes: 27 additions & 0 deletions astroid/tests/unittest_brain_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,32 @@ def test_numpy_random_mtrand_functions_signature(self):
self.assertEqual(default_args_values, exact_kwargs_default_values)


@unittest.skipUnless(HAS_NUMPY, "This test requires the numpy library.")
class NumpyBrainCoreNumericTypesTest(SubTestWrapper):
"""
Test of all the missing types defined in numerictypes module.
"""
all_types = ['uint16', 'uint32', 'uint64', 'int128', 'uint128',
'float16', 'float32', 'float64', 'float80', 'float96',
'float128', 'float256', 'complex32', 'complex64', 'complex128',
'complex160', 'complex192', 'complex256', 'complex512',
'timedelta64', 'datetime64', 'unicode_', 'string_', 'object_']

def _inferred_numpy_attribute(self, attrib):
node = builder.extract_node("""
import numpy.core.numerictypes as tested_module
missing_type = tested_module.{:s}""".format(attrib))
return next(node.value.infer())

def test_numpy_core_types(self):
"""
Test that all defined types have ClassDef type.
"""
for typ in self.all_types:
with self.subTest(typ=typ):
inferred = self._inferred_numpy_attribute(typ)
self.assertIsInstance(inferred, nodes.ClassDef)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion astroid/tests/unittest_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -4273,7 +4273,7 @@ def test_duplicated_keyword_arguments(self):
self.assertIn('f', site.duplicated_keywords)


@unittest.expectedFailure
@unittest.skip
class ObjectDunderNewTest(unittest.TestCase):

def test_object_dunder_new_is_inferred_if_decorator(self):
Expand Down