8000 bpo-41905: added abc.update_abstractmethods by bentheiii · Pull Request #22485 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41905: added abc.update_abstractmethods #22485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 6, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
additional tests
  • Loading branch information
ben avrahami committed Oct 1, 2020
commit a5a9fd7e941bfe53a4178f75e6e312f287ba0771
34 changes: 34 additions & 0 deletions Lib/test/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,22 @@ class C(with_metaclass(abc_ABCMeta, A, B)):
pass
self.assertEqual(C.__class__, abc_ABCMeta)

def test_update_del(self):
class A(metaclass=abc_ABCMeta):
@abc.abstractmethod
def foo(self):
pass

del A.foo
self.assertEqual(A.__abstractmethods__, {'foo'})
self.assertFalse(hasattr(A, 'foo'))

abc.update_abstractmethods(A)

self.assertEqual(A.__abstractmethods__, set())
A()


def test_update_new_abstractmethods(self):
class A(metaclass=abc_ABCMeta):
@abc.abstractmethod
Expand Down Expand Up @@ -524,6 +540,24 @@ class B(A):
B()
self.assertEqual(B.__abstractmethods__, set())

Copy link
Member
@iritkatriel iritkatriel Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need this test case to cover the first loop:

import abc
class FooABC(metaclass=abc.ABCMeta):
    @abc.abstractmethod
    def bar(self):
        pass

del FooABC.bar
assert ('bar' in FooABC.__abstractmethods__)
assert ('bar' not in FooABC.__dict__)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iritkatriel What does that test case accomplish other than showing that FooABC is now in an inconsistent state?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gvanrossum In this comment I left out the update_abstractmethods, see Ben's version which he committed as test_update_del. Without this test the first loop in update_abstractmethods was not exercised.

def test_update_asdecorator(self):
class A(metaclass=abc_ABCMeta):
@abc.abstractmethod
def foo(self):
pass

def class_decorator(cls):
cls.foo = lambda self: None
return cls

@abc.update_abstractmethods
@class_decorator
class B(A):
pass

B()
self.assertEqual(B.__abstractmethods__, set())


class TestABCWithInitSubclass(unittest.TestCase):
def test_works_with_init_subclass(self):
Expand Down
0