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
3f015a64
Kaydet (Commit)
3f015a64
authored
Agu 19, 2016
tarafından
Berker Peksag
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27157: Make only type() itself accept the one-argument form
Patch by Eryk Sun and Emanuel Barry.
üst
2a400fd6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
+30
-4
functions.rst
Doc/library/functions.rst
+3
-0
test_types.py
Lib/test/test_types.py
+18
-0
NEWS
Misc/NEWS
+3
-0
typeobject.c
Objects/typeobject.c
+6
-4
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
3f015a64
...
@@ -1463,6 +1463,9 @@ are always available. They are listed here in alphabetical order.
...
@@ -1463,6 +1463,9 @@ are always available. They are listed here in alphabetical order.
See also :ref:`bltin-type-objects`.
See also :ref:`bltin-type-objects`.
.. versionchanged:: 3.6
Subclasses of :class:`type` which don't override ``type.__new__`` may no
longer use the one-argument form to get the type of an object.
.. function:: vars([object])
.. function:: vars([object])
...
...
Lib/test/test_types.py
Dosyayı görüntüle @
3f015a64
...
@@ -1000,6 +1000,24 @@ class ClassCreationTests(unittest.TestCase):
...
@@ -1000,6 +1000,24 @@ class ClassCreationTests(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
with
self
.
assertRaises
(
TypeError
):
X
=
types
.
new_class
(
"X"
,
(
int
(),
C
))
X
=
types
.
new_class
(
"X"
,
(
int
(),
C
))
def
test_one_argument_type
(
self
):
expected_message
=
'type.__new__() takes exactly 3 arguments (1 given)'
# Only type itself can use the one-argument form (#27157)
self
.
assertIs
(
type
(
5
),
int
)
class
M
(
type
):
pass
with
self
.
assertRaises
(
TypeError
)
as
cm
:
M
(
5
)
self
.
assertEqual
(
str
(
cm
.
exception
),
expected_message
)
class
N
(
type
,
metaclass
=
M
):
pass
with
self
.
assertRaises
(
TypeError
)
as
cm
:
N
(
5
)
self
.
assertEqual
(
str
(
cm
.
exception
),
expected_message
)
class
SimpleNamespaceTests
(
unittest
.
TestCase
):
class
SimpleNamespaceTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
Dosyayı görüntüle @
3f015a64
...
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 1
...
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 1
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #27157: Make only type() itself accept the one-argument form.
Patch by Eryk Sun and Emanuel Barry.
- Issue #27558: Fix a SystemError in the implementation of "raise" statement.
- Issue #27558: Fix a SystemError in the implementation of "raise" statement.
In a brand new thread, raise a RuntimeError since there is no active
In a brand new thread, raise a RuntimeError since there is no active
exception to reraise. Patch written by Xiang Zhang.
exception to reraise. Patch written by Xiang Zhang.
...
...
Objects/typeobject.c
Dosyayı görüntüle @
3f015a64
...
@@ -2287,11 +2287,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -2287,11 +2287,13 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
assert
(
kwds
==
NULL
||
PyDict_Check
(
kwds
));
assert
(
kwds
==
NULL
||
PyDict_Check
(
kwds
));
/* Special case: type(x) should return x->ob_type */
/* Special case: type(x) should return x->ob_type */
{
/* We only want type itself to accept the one-argument form (#27157)
Note: We don't call PyType_CheckExact as that also allows subclasses */
if
(
metatype
==
&
PyType_Type
)
{
const
Py_ssize_t
nargs
=
PyTuple_GET_SIZE
(
args
);
const
Py_ssize_t
nargs
=
PyTuple_GET_SIZE
(
args
);
const
Py_ssize_t
nkwds
=
kwds
==
NULL
?
0
:
PyDict_Size
(
kwds
);
const
Py_ssize_t
nkwds
=
kwds
==
NULL
?
0
:
PyDict_Size
(
kwds
);
if
(
PyType_CheckExact
(
metatype
)
&&
nargs
==
1
&&
nkwds
==
0
)
{
if
(
nargs
==
1
&&
nkwds
==
0
)
{
PyObject
*
x
=
PyTuple_GET_ITEM
(
args
,
0
);
PyObject
*
x
=
PyTuple_GET_ITEM
(
args
,
0
);
Py_INCREF
(
Py_TYPE
(
x
));
Py_INCREF
(
Py_TYPE
(
x
));
return
(
PyObject
*
)
Py_TYPE
(
x
);
return
(
PyObject
*
)
Py_TYPE
(
x
);
...
@@ -2308,8 +2310,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
...
@@ -2308,8 +2310,8 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
}
/* Check arguments: (name, bases, dict) */
/* Check arguments: (name, bases, dict) */
if
(
!
PyArg_ParseTuple
(
args
,
"UO!O!:type
"
,
&
name
,
&
PyTuple_Type
,
&
bases
,
if
(
!
PyArg_ParseTuple
(
args
,
"UO!O!:type
.__new__"
,
&
name
,
&
PyTuple_Type
,
&
PyDict_Type
,
&
orig_dict
))
&
bases
,
&
PyDict_Type
,
&
orig_dict
))
return
NULL
;
return
NULL
;
/* Determine the proper metatype to deal with this: */
/* Determine the proper metatype to deal with this: */
...
...
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