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
3018cc49
Kaydet (Commit)
3018cc49
authored
Tem 18, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24206: Fixed __eq__ and __ne__ methods of inspect classes.
üst
d113c967
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
36 deletions
+64
-36
inspect.py
Lib/inspect.py
+9
-15
test_inspect.py
Lib/test/test_inspect.py
+53
-21
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/inspect.py
Dosyayı görüntüle @
3018cc49
...
@@ -2206,15 +2206,13 @@ class Parameter:
...
@@ -2206,15 +2206,13 @@ class Parameter:
id
(
self
),
self
.
name
)
id
(
self
),
self
.
name
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
issubclass
(
other
.
__class__
,
Parameter
)
and
if
not
isinstance
(
other
,
Parameter
):
self
.
_name
==
other
.
_name
and
return
NotImplemented
return
(
self
.
_name
==
other
.
_name
and
self
.
_kind
==
other
.
_kind
and
self
.
_kind
==
other
.
_kind
and
self
.
_default
==
other
.
_default
and
self
.
_default
==
other
.
_default
and
self
.
_annotation
==
other
.
_annotation
)
self
.
_annotation
==
other
.
_annotation
)
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
class
BoundArguments
:
class
BoundArguments
:
'''Result of `Signature.bind` call. Holds the mapping of arguments
'''Result of `Signature.bind` call. Holds the mapping of arguments
...
@@ -2295,13 +2293,11 @@ class BoundArguments:
...
@@ -2295,13 +2293,11 @@ class BoundArguments:
return
kwargs
return
kwargs
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
issubclass
(
other
.
__class__
,
BoundArguments
)
and
if
not
isinstance
(
other
,
BoundArguments
):
self
.
signature
==
other
.
signature
and
return
NotImplemented
return
(
self
.
signature
==
other
.
signature
and
self
.
arguments
==
other
.
arguments
)
self
.
arguments
==
other
.
arguments
)
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
class
Signature
:
class
Signature
:
'''A Signature object represents the overall signature of a function.
'''A Signature object represents the overall signature of a function.
...
@@ -2493,8 +2489,9 @@ class Signature:
...
@@ -2493,8 +2489,9 @@ class Signature:
return_annotation
=
return_annotation
)
return_annotation
=
return_annotation
)
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
if
(
not
issubclass
(
type
(
other
),
Signature
)
or
if
not
isinstance
(
other
,
Signature
):
self
.
return_annotation
!=
other
.
return_annotation
or
return
NotImplemented
if
(
self
.
return_annotation
!=
other
.
return_annotation
or
len
(
self
.
parameters
)
!=
len
(
other
.
parameters
)):
len
(
self
.
parameters
)
!=
len
(
other
.
parameters
)):
return
False
return
False
...
@@ -2522,9 +2519,6 @@ class Signature:
...
@@ -2522,9 +2519,6 @@ class Signature:
return
True
return
True
def
__ne__
(
self
,
other
):
return
not
self
.
__eq__
(
other
)
def
_bind
(
self
,
args
,
kwargs
,
*
,
partial
=
False
):
def
_bind
(
self
,
args
,
kwargs
,
*
,
partial
=
False
):
'''Private method. Don't use directly.'''
'''Private method. Don't use directly.'''
...
...
Lib/test/test_inspect.py
Dosyayı görüntüle @
3018cc49
...
@@ -76,6 +76,10 @@ def generator_function_example(self):
...
@@ -76,6 +76,10 @@ def generator_function_example(self):
for
i
in
range
(
2
):
for
i
in
range
(
2
):
yield
i
yield
i
class
EqualsToAll
:
def
__eq__
(
self
,
other
):
return
True
class
TestPredicates
(
IsTestBase
):
class
TestPredicates
(
IsTestBase
):
def
test_sixteen
(
self
):
def
test_sixteen
(
self
):
count
=
len
([
x
for
x
in
dir
(
inspect
)
if
x
.
startswith
(
'is'
)])
count
=
len
([
x
for
x
in
dir
(
inspect
)
if
x
.
startswith
(
'is'
)])
...
@@ -2459,47 +2463,62 @@ class TestSignatureObject(unittest.TestCase):
...
@@ -2459,47 +2463,62 @@ class TestSignatureObject(unittest.TestCase):
def
test_signature_equality
(
self
):
def
test_signature_equality
(
self
):
def
foo
(
a
,
*
,
b
:
int
)
->
float
:
pass
def
foo
(
a
,
*
,
b
:
int
)
->
float
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
42
)
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
42
)
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
42
)
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
EqualsToAll
())
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
EqualsToAll
())
def
bar
(
a
,
*
,
b
:
int
)
->
float
:
pass
def
bar
(
a
,
*
,
b
:
int
)
->
float
:
pass
self
.
assertEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
bar
(
a
,
*
,
b
:
int
)
->
int
:
pass
def
bar
(
a
,
*
,
b
:
int
)
->
int
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
bar
(
a
,
*
,
b
:
int
):
pass
def
bar
(
a
,
*
,
b
:
int
):
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
bar
(
a
,
*
,
b
:
int
=
42
)
->
float
:
pass
def
bar
(
a
,
*
,
b
:
int
=
42
)
->
float
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
bar
(
a
,
*
,
c
)
->
float
:
pass
def
bar
(
a
,
*
,
c
)
->
float
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
bar
(
a
,
b
:
int
)
->
float
:
pass
def
bar
(
a
,
b
:
int
)
->
float
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
spam
(
b
:
int
,
a
)
->
float
:
pass
def
spam
(
b
:
int
,
a
)
->
float
:
pass
self
.
assertNotEqual
(
inspect
.
signature
(
spam
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
spam
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
spam
)
!=
inspect
.
signature
(
bar
))
def
foo
(
*
,
a
,
b
,
c
):
pass
def
foo
(
*
,
a
,
b
,
c
):
pass
def
bar
(
*
,
c
,
b
,
a
):
pass
def
bar
(
*
,
c
,
b
,
a
):
pass
self
.
assertEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
foo
(
*
,
a
=
1
,
b
,
c
):
pass
def
foo
(
*
,
a
=
1
,
b
,
c
):
pass
def
bar
(
*
,
c
,
b
,
a
=
1
):
pass
def
bar
(
*
,
c
,
b
,
a
=
1
):
pass
self
.
assertEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
foo
(
pos
,
*
,
a
=
1
,
b
,
c
):
pass
def
foo
(
pos
,
*
,
a
=
1
,
b
,
c
):
pass
def
bar
(
pos
,
*
,
c
,
b
,
a
=
1
):
pass
def
bar
(
pos
,
*
,
c
,
b
,
a
=
1
):
pass
self
.
assertEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
foo
(
pos
,
*
,
a
,
b
,
c
):
pass
def
foo
(
pos
,
*
,
a
,
b
,
c
):
pass
def
bar
(
pos
,
*
,
c
,
b
,
a
=
1
):
pass
def
bar
(
pos
,
*
,
c
,
b
,
a
=
1
):
pass
self
.
assertNotEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
foo
(
pos
,
*
args
,
a
=
42
,
b
,
c
,
**
kwargs
:
int
):
pass
def
foo
(
pos
,
*
args
,
a
=
42
,
b
,
c
,
**
kwargs
:
int
):
pass
def
bar
(
pos
,
*
args
,
c
,
b
,
a
=
42
,
**
kwargs
:
int
):
pass
def
bar
(
pos
,
*
args
,
c
,
b
,
a
=
42
,
**
kwargs
:
int
):
pass
self
.
assertEqual
(
inspect
.
signature
(
foo
),
inspect
.
signature
(
bar
))
self
.
assertTrue
(
inspect
.
signature
(
foo
)
==
inspect
.
signature
(
bar
))
self
.
assertFalse
(
inspect
.
signature
(
foo
)
!=
inspect
.
signature
(
bar
))
def
test_signature_unhashable
(
self
):
def
test_signature_unhashable
(
self
):
def
foo
(
a
):
pass
def
foo
(
a
):
pass
...
@@ -2629,10 +2648,16 @@ class TestParameterObject(unittest.TestCase):
...
@@ -2629,10 +2648,16 @@ class TestParameterObject(unittest.TestCase):
P
=
inspect
.
Parameter
P
=
inspect
.
Parameter
p
=
P
(
'foo'
,
default
=
42
,
kind
=
inspect
.
Parameter
.
KEYWORD_ONLY
)
p
=
P
(
'foo'
,
default
=
42
,
kind
=
inspect
.
Parameter
.
KEYWORD_ONLY
)
self
.
assertEqual
(
p
,
p
)
self
.
assertTrue
(
p
==
p
)
self
.
assertNotEqual
(
p
,
42
)
self
.
assertFalse
(
p
!=
p
)
self
.
assertFalse
(
p
==
42
)
self
.
assertTrue
(
p
!=
42
)
self
.
assertTrue
(
p
==
EqualsToAll
())
self
.
assertFalse
(
p
!=
EqualsToAll
())
self
.
assertEqual
(
p
,
P
(
'foo'
,
default
=
42
,
self
.
assertTrue
(
p
==
P
(
'foo'
,
default
=
42
,
kind
=
inspect
.
Parameter
.
KEYWORD_ONLY
))
self
.
assertFalse
(
p
!=
P
(
'foo'
,
default
=
42
,
kind
=
inspect
.
Parameter
.
KEYWORD_ONLY
))
kind
=
inspect
.
Parameter
.
KEYWORD_ONLY
))
def
test_signature_parameter_unhashable
(
self
):
def
test_signature_parameter_unhashable
(
self
):
...
@@ -2936,19 +2961,26 @@ class TestBoundArguments(unittest.TestCase):
...
@@ -2936,19 +2961,26 @@ class TestBoundArguments(unittest.TestCase):
def
test_signature_bound_arguments_equality
(
self
):
def
test_signature_bound_arguments_equality
(
self
):
def
foo
(
a
):
pass
def
foo
(
a
):
pass
ba
=
inspect
.
signature
(
foo
)
.
bind
(
1
)
ba
=
inspect
.
signature
(
foo
)
.
bind
(
1
)
self
.
assertEqual
(
ba
,
ba
)
self
.
assertTrue
(
ba
==
ba
)
self
.
assertFalse
(
ba
!=
ba
)
self
.
assertTrue
(
ba
==
EqualsToAll
())
self
.
assertFalse
(
ba
!=
EqualsToAll
())
ba2
=
inspect
.
signature
(
foo
)
.
bind
(
1
)
ba2
=
inspect
.
signature
(
foo
)
.
bind
(
1
)
self
.
assertEqual
(
ba
,
ba2
)
self
.
assertTrue
(
ba
==
ba2
)
self
.
assertFalse
(
ba
!=
ba2
)
ba3
=
inspect
.
signature
(
foo
)
.
bind
(
2
)
ba3
=
inspect
.
signature
(
foo
)
.
bind
(
2
)
self
.
assertNotEqual
(
ba
,
ba3
)
self
.
assertFalse
(
ba
==
ba3
)
self
.
assertTrue
(
ba
!=
ba3
)
ba3
.
arguments
[
'a'
]
=
1
ba3
.
arguments
[
'a'
]
=
1
self
.
assertEqual
(
ba
,
ba3
)
self
.
assertTrue
(
ba
==
ba3
)
self
.
assertFalse
(
ba
!=
ba3
)
def
bar
(
b
):
pass
def
bar
(
b
):
pass
ba4
=
inspect
.
signature
(
bar
)
.
bind
(
1
)
ba4
=
inspect
.
signature
(
bar
)
.
bind
(
1
)
self
.
assertNotEqual
(
ba
,
ba4
)
self
.
assertFalse
(
ba
==
ba4
)
self
.
assertTrue
(
ba
!=
ba4
)
class
TestSignaturePrivateHelpers
(
unittest
.
TestCase
):
class
TestSignaturePrivateHelpers
(
unittest
.
TestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
3018cc49
...
@@ -66,6 +66,8 @@ Core and Builtins
...
@@ -66,6 +66,8 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
24206
:
Fixed
__eq__
and
__ne__
methods
of
inspect
classes
.
-
Issue
#
21750
:
mock_open
.
read_data
can
now
be
read
from
each
instance
,
as
it
-
Issue
#
21750
:
mock_open
.
read_data
can
now
be
read
from
each
instance
,
as
it
could
in
Python
3.3
.
could
in
Python
3.3
.
...
...
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