Skip to content

Commit 8438deb

Browse files
committed
super() without arguments requires v3+
1 parent b6a7942 commit 8438deb

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

tests/builtin_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def test_sum(self):
5050
self.assertOnlyIn(((2, 3), (3, 0)), self.detect("sum()"))
5151

5252
def test_super(self):
53-
self.assertOnlyIn(((2, 2), (3, 0)), self.detect("super()"))
53+
# Calling without arguments requires v3 (`SourceVisitor.super_no_args()`).
54+
self.assertOnlyIn(((2, 2), (3, 0)), self.detect("super(SomeType)"))
5455

5556
def test_unichr(self):
5657
self.assertOnlyIn((2, 0), self.detect("unichr()"))

tests/lang.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,3 +1830,22 @@ def square(number: int | float) -> int | float:
18301830
""")
18311831
self.assertTrue(visitor.union_types())
18321832
self.assertOnlyIn((3, 10), visitor.minimum_versions())
1833+
1834+
def test_super_no_args(self):
1835+
# Without arguments, it's v3.0.
1836+
visitor = self.visit("""
1837+
class Foo:
1838+
def test(self):
1839+
super()
1840+
""")
1841+
self.assertTrue(visitor.super_no_args())
1842+
self.assertOnlyIn((3, 0), visitor.minimum_versions())
1843+
1844+
# With arguments, the mininmum of super() is v2.2/3.0.
1845+
visitor = self.visit("""
1846+
class Foo:
1847+
def test(self):
1848+
super(Foo, self)
1849+
""")
1850+
self.assertFalse(visitor.super_no_args())
1851+
self.assertOnlyIn(((2, 2), (3, 0)), visitor.minimum_versions())

vermin/source_visitor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def __init__(self, config, path=None):
146146
self.__builtin_types = {"dict", "set", "list", "unicode", "str", "int", "float", "long",
147147
"bytes"}
148148
self.__codecs_encodings_kwargs = ("encoding", "data_encoding", "file_encoding")
149+
self.__super_no_args = False
149150

150151
# Imported members of modules, like "exc_clear" of "sys".
151152
self.__import_mem_mod = {}
@@ -360,6 +361,9 @@ def union_types(self):
360361
def pattern_matching(self):
361362
return self.__pattern_matching
362363

364+
def super_no_args(self):
365+
return self.__super_no_args
366+
363367
def __violates_target_versions(self, versions):
364368
# If only violations isn't turned on then fake violations because it means it will show the
365369
# rule.
@@ -547,6 +551,9 @@ def minimum_versions(self):
547551
if self.union_types():
548552
mins = self.__add_versions_entity(mins, (None, (3, 10)), "union types as `X | Y`")
549553

554+
if self.super_no_args():
555+
mins = self.__add_versions_entity(mins, (None, (3, 0)), "super() without arguments")
556+
550557
for directive in self.strftime_directives():
551558
if directive in STRFTIME_REQS:
552559
vers = STRFTIME_REQS[directive]
@@ -1112,6 +1119,9 @@ def visit_Call(self, node):
11121119
is_int_node(node.args[2]):
11131120
self.__mod_inverse_pow = True
11141121
self.__vvprint("modular inverse pow()", versions=[None, (3, 8)])
1122+
elif func.id == "super" and len(node.args) == 0:
1123+
self.__super_no_args = True
1124+
self.__vvprint("super() without arguments", versions=[None, (3, 0)])
11151125
elif hasattr(func, "attr"):
11161126
attr = func.attr
11171127
if attr == "format" and hasattr(func, "value") and isinstance(func.value, ast.Str) and \

0 commit comments

Comments
 (0)