Skip to content

Commit b104183

Browse files
authored
Merge pull request RustPython#1667 from youknowone/whatsleft
whats_left prints inherited but unimplemented attrs + more types
2 parents 156e6e1 + 5389ab0 commit b104183

File tree

2 files changed

+62
-15
lines changed

2 files changed

+62
-15
lines changed
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
not_implemented = [(name, method)
2-
for name, (val, methods) in expected_methods.items()
3-
for method in methods
4-
if not hasattr(val, method)]
5-
6-
for r in not_implemented:
7-
print(r[0], ".", r[1], sep="")
8-
if not not_implemented:
1+
2+
def attr_is_not_inherited(type_, attr):
3+
"""
4+
returns True if type_'s attr is not inherited from any of its base classes
5+
"""
6+
bases = type_.__mro__[1:]
7+
8+
return getattr(type_, attr) not in (getattr(base, attr, None) for base in bases)
9+
10+
11+
not_implementeds = []
12+
for name, (typ, methods) in expected_methods.items():
13+
for method in methods:
14+
has_method = hasattr(typ, method)
15+
is_inherited = has_method and not attr_is_not_inherited(typ, method)
16+
if has_method and not is_inherited:
17+
continue
18+
not_implementeds.append((name, method, is_inherited))
19+
20+
for r in not_implementeds:
21+
print(r[0], ".", r[1], " (inherited)" if r[2] else "", sep="")
22+
if not not_implementeds:
923
print("Not much \\o/")
1024

1125
if platform.python_implementation() == "CPython":
12-
assert len(not_implemented) == 0, "CPython should have all the methods"
26+
assert len(not_implementeds) == 0, "CPython should have all the methods"

tests/not_impl_gen.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,70 @@ def attr_is_not_inherited(type_, attr):
2626

2727

2828
def gen_methods(header, footer, output):
29-
objects = [
29+
types = [
3030
bool,
3131
bytearray,
3232
bytes,
3333
complex,
3434
dict,
35+
enumerate,
36+
filter,
3537
float,
3638
frozenset,
3739
int,
3840
list,
41+
map,
3942
memoryview,
4043
range,
4144
set,
45+
slice,
4246
str,
47+
super,
4348
tuple,
4449
object,
50+
zip,
51+
52+
classmethod,
53+
staticmethod,
54+
property,
55+
56+
Exception,
57+
BaseException,
58+
]
59+
objects = [(t.__name__, t.__name__) for t in types]
60+
objects.extend([
61+
('NoneType', 'type(None)'),
62+
])
63+
64+
iters = [
65+
('bytearray_iterator', 'type(bytearray().__iter__())'),
66+
('bytes_iterator', 'type(bytes().__iter__())'),
67+
('dict_keyiterator', 'type(dict().__iter__())'),
68+
('dict_valueiterator', 'type(dict().values().__iter__())'),
69+
('dict_itemiterator', 'type(dict().items().__iter__())'),
70+
('dict_values', 'type(dict().values())'),
71+
('dict_items', 'type(dict().items())'),
72+
('set_iterator', 'type(set().__iter__())'),
73+
('list_iterator', 'type(list().__iter__())'),
74+
('range_iterator', 'type(range(0).__iter__())'),
75+
('str_iterator', 'type(str().__iter__())'),
76+
('tuple_iterator', 'type(tuple().__iter__())'),
4577
]
4678

4779
output.write(header.read())
4880
output.write("expected_methods = {\n")
4981

50-
for obj in objects:
51-
output.write(f" '{obj.__name__}': ({obj.__name__}, [\n")
82+
for name, typ_code in objects + iters:
83+
typ = eval(typ_code)
84+
output.write(f" '{name}': ({typ_code}, [\n")
5285
output.write(
5386
"\n".join(
5487
f" {attr!r},"
55-
for attr in dir(obj)
56-
if attr_is_not_inherited(obj, attr)
88+
for attr in dir(typ)
89+
if attr_is_not_inherited(typ, attr)
5790
)
5891
)
59-
output.write("\n ])," + ("\n" if objects[-1] == obj else "\n\n"))
92+
output.write("\n ])," + ("\n" if objects[-1] == typ else "\n\n"))
6093

6194
output.write("}\n\n")
6295
output.write(footer.read())

0 commit comments

Comments
 (0)