Skip to content

Commit 4d77ff6

Browse files
[refactor] Remove variable for thing that never change in test_inference (pylint-dev#2243)
1 parent 8975066 commit 4d77ff6

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

tests/test_inference.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def get_node_of_class(start_from: nodes.FunctionDef, klass: type) -> nodes.Attri
5858

5959
builder = AstroidBuilder()
6060

61-
EXC_MODULE = "builtins"
62-
BOOL_SPECIAL_METHOD = "__bool__"
6361
DATA_DIR = Path(__file__).parent / "testdata" / "python3" / "data"
6462

6563

@@ -199,7 +197,7 @@ def test_tupleassign_name_inference(self) -> None:
199197
exc = next(inferred)
200198
self.assertIsInstance(exc, Instance)
201199
self.assertEqual(exc.name, "Exception")
202-
self.assertEqual(exc.root().name, EXC_MODULE)
200+
self.assertEqual(exc.root().name, "builtins")
203201
self.assertRaises(StopIteration, partial(next, inferred))
204202
inferred = self.ast["b"].infer()
205203
const = next(inferred)
@@ -217,7 +215,7 @@ def test_listassign_name_inference(self) -> None:
217215
exc = next(inferred)
218216
self.assertIsInstance(exc, Instance)
219217
self.assertEqual(exc.name, "Exception")
220-
self.assertEqual(exc.root().name, EXC_MODULE)
218+
self.assertEqual(exc.root().name, "builtins")
221219
self.assertRaises(StopIteration, partial(next, inferred))
222220
inferred = self.ast["e"].infer()
223221
const = next(inferred)
@@ -268,15 +266,15 @@ def test_swap_assign_inference(self) -> None:
268266
exc = next(inferred)
269267
self.assertIsInstance(exc, Instance)
270268
self.assertEqual(exc.name, "Exception")
271-
self.assertEqual(exc.root().name, EXC_MODULE)
269+
self.assertEqual(exc.root().name, "builtins")
272270
self.assertRaises(StopIteration, partial(next, inferred))
273271

274272
def test_getattr_inference1(self) -> None:
275273
inferred = self.ast["ex"].infer()
276274
exc = next(inferred)
277275
self.assertIsInstance(exc, Instance)
278276
self.assertEqual(exc.name, "Exception")
279-
self.assertEqual(exc.root().name, EXC_MODULE)
277+
self.assertEqual(exc.root().name, "builtins")
280278
self.assertRaises(StopIteration, partial(next, inferred))
281279

282280
def test_getattr_inference2(self) -> None:
@@ -536,13 +534,13 @@ class Warning(Warning):
536534
ancestors = w.ancestors()
537535
ancestor = next(ancestors)
538536
self.assertEqual(ancestor.name, "Warning")
539-
self.assertEqual(ancestor.root().name, EXC_MODULE)
537+
self.assertEqual(ancestor.root().name, "builtins")
540538
ancestor = next(ancestors)
541539
self.assertEqual(ancestor.name, "Exception")
542-
self.assertEqual(ancestor.root().name, EXC_MODULE)
540+
self.assertEqual(ancestor.root().name, "builtins")
543541
ancestor = next(ancestors)
544542
self.assertEqual(ancestor.name, "BaseException")
545-
self.assertEqual(ancestor.root().name, EXC_MODULE)
543+
self.assertEqual(ancestor.root().name, "builtins")
546544
ancestor = next(ancestors)
547545
self.assertEqual(ancestor.name, "object")
548546
self.assertEqual(ancestor.root().name, "builtins")
@@ -2889,12 +2887,12 @@ def true_value():
28892887

28902888
def test_bool_value_instances(self) -> None:
28912889
instances = extract_node(
2892-
f"""
2890+
"""
28932891
class FalseBoolInstance(object):
2894-
def {BOOL_SPECIAL_METHOD}(self):
2892+
def __bool__(self):
28952893
return False
28962894
class TrueBoolInstance(object):
2897-
def {BOOL_SPECIAL_METHOD}(self):
2895+
def __bool__(self):
28982896
return True
28992897
class FalseLenInstance(object):
29002898
def __len__(self):
@@ -2927,11 +2925,11 @@ class NonMethods(object):
29272925

29282926
def test_bool_value_variable(self) -> None:
29292927
instance = extract_node(
2930-
f"""
2928+
"""
29312929
class VariableBoolInstance(object):
29322930
def __init__(self, value):
29332931
self.value = value
2934-
def {BOOL_SPECIAL_METHOD}(self):
2932+
def __bool__(self):
29352933
return self.value
29362934
29372935
not VariableBoolInstance(True)
@@ -4856,20 +4854,20 @@ def test_bool(self) -> None:
48564854

48574855
def test_bool_bool_special_method(self) -> None:
48584856
ast_nodes = extract_node(
4859-
f"""
4857+
"""
48604858
class FalseClass:
4861-
def {BOOL_SPECIAL_METHOD}(self):
4859+
def __bool__(self):
48624860
return False
48634861
class TrueClass:
4864-
def {BOOL_SPECIAL_METHOD}(self):
4862+
def __bool__(self):
48654863
return True
48664864
class C(object):
48674865
def __call__(self):
48684866
return False
48694867
class B(object):
4870-
{BOOL_SPECIAL_METHOD} = C()
4868+
__bool__ = C()
48714869
class LambdaBoolFalse(object):
4872-
{BOOL_SPECIAL_METHOD} = lambda self: self.foo
4870+
__bool__ = lambda self: self.foo
48734871
@property
48744872
def foo(self): return 0
48754873
class FalseBoolLen(object):
@@ -4892,9 +4890,9 @@ def foo(self): return 0
48924890

48934891
def test_bool_instance_not_callable(self) -> None:
48944892
ast_nodes = extract_node(
4895-
f"""
4893+
"""
48964894
class BoolInvalid(object):
4897-
{BOOL_SPECIAL_METHOD} = 42
4895+
__bool__ = 42
48984896
class LenInvalid(object):
48994897
__len__ = "a"
49004898
bool(BoolInvalid()) #@

0 commit comments

Comments
 (0)