Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
34997327
Commit
34997327
authored
Jan 07, 2008
by
Jeffrey Yasskin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix issue 1747: allow classic classes to be checked for being subclasses of
ABCs.
parent
80ab1d2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
Lib/abc.py
Lib/abc.py
+1
-1
Lib/test/test_abc.py
Lib/test/test_abc.py
+11
-4
No files found.
Lib/abc.py
View file @
34997327
...
...
@@ -188,7 +188,7 @@ class ABCMeta(type):
cls
.
_abc_negative_cache
.
add
(
subclass
)
return
ok
# Check if it's a direct subclass
if
cls
in
subclass
.
__mro__
:
if
cls
in
getattr
(
subclass
,
'__mro__'
,
())
:
cls
.
_abc_cache
.
add
(
subclass
)
return
True
# Check if it's a subclass of a registered class (recursive)
...
...
Lib/test/test_abc.py
View file @
34997327
...
...
@@ -8,7 +8,6 @@ import unittest
from
test
import
test_support
import
abc
__metaclass__
=
type
class
TestABC
(
unittest
.
TestCase
):
...
...
@@ -59,10 +58,18 @@ class TestABC(unittest.TestCase):
self
.
assertEqual
(
F
.
__abstractmethods__
,
set
([
"bar"
]))
self
.
assertRaises
(
TypeError
,
F
)
# because bar is abstract now
def
test_subclass_oldstyle_class
(
self
):
class
A
:
__metaclass__
=
abc
.
ABCMeta
class
OldstyleClass
:
pass
self
.
assertFalse
(
issubclass
(
OldstyleClass
,
A
))
self
.
assertFalse
(
issubclass
(
A
,
OldstyleClass
))
def
test_registration_basics
(
self
):
class
A
:
__metaclass__
=
abc
.
ABCMeta
class
B
:
class
B
(
object
)
:
pass
b
=
B
()
self
.
assertEqual
(
issubclass
(
B
,
A
),
False
)
...
...
@@ -95,7 +102,7 @@ class TestABC(unittest.TestCase):
class
A1
(
A
):
pass
self
.
assertRaises
(
RuntimeError
,
A1
.
register
,
A
)
# cycles not allowed
class
B
:
class
B
(
object
)
:
pass
A1
.
register
(
B
)
# ok
A1
.
register
(
B
)
# should pass silently
...
...
@@ -136,7 +143,7 @@ class TestABC(unittest.TestCase):
def
test_all_new_methods_are_called
(
self
):
class
A
:
__metaclass__
=
abc
.
ABCMeta
class
B
:
class
B
(
object
)
:
counter
=
0
def
__new__
(
cls
):
B
.
counter
+=
1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment