Fix missing case for detecting future imports
PiperOrigin-RevId: 239268639
This commit is contained in:
parent
b5692e1e80
commit
4c86091df5
@ -298,7 +298,7 @@ def getfutureimports(entity):
|
|||||||
Returns:
|
Returns:
|
||||||
A tuple of future strings
|
A tuple of future strings
|
||||||
"""
|
"""
|
||||||
if not tf_inspect.isfunction(entity):
|
if not (tf_inspect.isfunction(entity) or tf_inspect.ismethod(entity)):
|
||||||
return tuple()
|
return tuple()
|
||||||
return tuple(sorted(name for name, value in entity.__globals__.items()
|
return tuple(sorted(name for name, value in entity.__globals__.items()
|
||||||
if getattr(value, '__module__', None) == '__future__'))
|
if getattr(value, '__module__', None) == '__future__'))
|
||||||
|
@ -415,12 +415,18 @@ class InspectUtilsTest(test.TestCase):
|
|||||||
self.assertTrue(inspect_utils.isbuiltin(zip))
|
self.assertTrue(inspect_utils.isbuiltin(zip))
|
||||||
self.assertFalse(inspect_utils.isbuiltin(function_decorator))
|
self.assertFalse(inspect_utils.isbuiltin(function_decorator))
|
||||||
|
|
||||||
def test_getfutureimports_simple_case(self):
|
def test_getfutureimports_functions(self):
|
||||||
expected_imports = ('absolute_import', 'division', 'print_function',
|
expected_imports = ('absolute_import', 'division', 'print_function',
|
||||||
'with_statement')
|
'with_statement')
|
||||||
self.assertEqual(inspect_utils.getfutureimports(future_import_module.f),
|
self.assertEqual(inspect_utils.getfutureimports(future_import_module.f),
|
||||||
expected_imports)
|
expected_imports)
|
||||||
|
|
||||||
|
def test_getfutureimports_methods(self):
|
||||||
|
expected_imports = ('absolute_import', 'division', 'print_function',
|
||||||
|
'with_statement')
|
||||||
|
self.assertEqual(inspect_utils.getfutureimports(future_import_module.Foo.f),
|
||||||
|
expected_imports)
|
||||||
|
|
||||||
def test_super_wrapper_for_dynamic_attrs(self):
|
def test_super_wrapper_for_dynamic_attrs(self):
|
||||||
|
|
||||||
a = object()
|
a = object()
|
||||||
|
@ -24,3 +24,9 @@ from __future__ import with_statement
|
|||||||
|
|
||||||
def f():
|
def f():
|
||||||
print('foo')
|
print('foo')
|
||||||
|
|
||||||
|
|
||||||
|
class Foo(object):
|
||||||
|
|
||||||
|
def f(self):
|
||||||
|
print('foo')
|
||||||
|
Loading…
Reference in New Issue
Block a user