Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b9e15f75
Kaydet (Commit)
b9e15f75
authored
Mar 17, 2008
tarafından
Jeffrey Yasskin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make isinstance(OldstyleClass, NewstyleClass) return False instead of raising
an exception. Issue reported by Joseph Armbruster.
üst
1b4e45ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
abc.py
Lib/abc.py
+5
-5
test_abc.py
Lib/test/test_abc.py
+11
-0
No files found.
Lib/abc.py
Dosyayı görüntüle @
b9e15f75
...
@@ -116,18 +116,18 @@ class ABCMeta(type):
...
@@ -116,18 +116,18 @@ class ABCMeta(type):
def
__instancecheck__
(
cls
,
instance
):
def
__instancecheck__
(
cls
,
instance
):
"""Override for isinstance(instance, cls)."""
"""Override for isinstance(instance, cls)."""
# Inline the cache checking
for new-style classes
.
# Inline the cache checking
when it's simple
.
subclass
=
instance
.
__class__
subclass
=
getattr
(
instance
,
'__class__'
,
None
)
if
subclass
in
cls
.
_abc_cache
:
if
subclass
in
cls
.
_abc_cache
:
return
True
return
True
subtype
=
type
(
instance
)
subtype
=
type
(
instance
)
if
subtype
is
subclass
:
if
subtype
is
subclass
or
subclass
is
None
:
if
(
cls
.
_abc_negative_cache_version
==
if
(
cls
.
_abc_negative_cache_version
==
ABCMeta
.
_abc_invalidation_counter
and
ABCMeta
.
_abc_invalidation_counter
and
sub
class
in
cls
.
_abc_negative_cache
):
sub
type
in
cls
.
_abc_negative_cache
):
return
False
return
False
# Fall back to the subclass check.
# Fall back to the subclass check.
return
cls
.
__subclasscheck__
(
sub
class
)
return
cls
.
__subclasscheck__
(
sub
type
)
return
(
cls
.
__subclasscheck__
(
subclass
)
or
return
(
cls
.
__subclasscheck__
(
subclass
)
or
cls
.
__subclasscheck__
(
subtype
))
cls
.
__subclasscheck__
(
subtype
))
...
...
Lib/test/test_abc.py
Dosyayı görüntüle @
b9e15f75
...
@@ -70,6 +70,17 @@ class TestABC(unittest.TestCase):
...
@@ -70,6 +70,17 @@ class TestABC(unittest.TestCase):
self
.
assertFalse
(
issubclass
(
OldstyleClass
,
A
))
self
.
assertFalse
(
issubclass
(
OldstyleClass
,
A
))
self
.
assertFalse
(
issubclass
(
A
,
OldstyleClass
))
self
.
assertFalse
(
issubclass
(
A
,
OldstyleClass
))
def
test_isinstance_class
(
self
):
class
A
:
__metaclass__
=
abc
.
ABCMeta
class
OldstyleClass
:
pass
self
.
assertFalse
(
isinstance
(
OldstyleClass
,
A
))
self
.
assertTrue
(
isinstance
(
OldstyleClass
,
type
(
OldstyleClass
)))
self
.
assertFalse
(
isinstance
(
A
,
OldstyleClass
))
# This raises a recursion depth error, but is low-priority:
# self.assertTrue(isinstance(A, abc.ABCMeta))
def
test_registration_basics
(
self
):
def
test_registration_basics
(
self
):
class
A
:
class
A
:
__metaclass__
=
abc
.
ABCMeta
__metaclass__
=
abc
.
ABCMeta
...
...
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