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
43d12a6b
Unverified
Kaydet (Commit)
43d12a6b
authored
May 09, 2018
tarafından
Ivan Levkivskyi
Kaydeden (comit)
GitHub
May 09, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-28556: Minor fixes for typing module (GH-6732)
This also fixes
https://bugs.python.org/issue33420
üst
0904f766
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
2 deletions
+79
-2
test_typing.py
Lib/test/test_typing.py
+68
-0
typing.py
Lib/typing.py
+8
-2
2018-05-08-16-43-42.bpo-28556._xr5mp.rst
...S.d/next/Library/2018-05-08-16-43-42.bpo-28556._xr5mp.rst
+3
-0
No files found.
Lib/test/test_typing.py
Dosyayı görüntüle @
43d12a6b
...
...
@@ -1324,6 +1324,72 @@ class GenericTests(BaseTestCase):
with
self
.
assertRaises
(
Exception
):
D
[
T
]
def
test_new_with_args
(
self
):
class
A
(
Generic
[
T
]):
pass
class
B
:
def
__new__
(
cls
,
arg
):
# call object
obj
=
super
()
.
__new__
(
cls
)
obj
.
arg
=
arg
return
obj
# mro: C, A, Generic, B, object
class
C
(
A
,
B
):
pass
c
=
C
(
'foo'
)
self
.
assertEqual
(
c
.
arg
,
'foo'
)
def
test_new_with_args2
(
self
):
class
A
:
def
__init__
(
self
,
arg
):
self
.
from_a
=
arg
# call object
super
()
.
__init__
()
# mro: C, Generic, A, object
class
C
(
Generic
[
T
],
A
):
def
__init__
(
self
,
arg
):
self
.
from_c
=
arg
# call Generic
super
()
.
__init__
(
arg
)
c
=
C
(
'foo'
)
self
.
assertEqual
(
c
.
from_a
,
'foo'
)
self
.
assertEqual
(
c
.
from_c
,
'foo'
)
def
test_new_no_args
(
self
):
class
A
(
Generic
[
T
]):
pass
class
B
:
def
__new__
(
cls
):
# call object
obj
=
super
()
.
__new__
(
cls
)
obj
.
from_b
=
'b'
return
obj
# mro: C, A, Generic, B, object
class
C
(
A
,
B
):
def
__init__
(
self
,
arg
):
self
.
arg
=
arg
def
__new__
(
cls
,
arg
):
# call A
obj
=
super
()
.
__new__
(
cls
)
obj
.
from_c
=
'c'
return
obj
c
=
C
(
'foo'
)
self
.
assertEqual
(
c
.
arg
,
'foo'
)
self
.
assertEqual
(
c
.
from_b
,
'b'
)
self
.
assertEqual
(
c
.
from_c
,
'c'
)
class
ClassVarTests
(
BaseTestCase
):
...
...
@@ -1737,6 +1803,8 @@ class GetTypeHintTests(BaseTestCase):
self
.
assertEqual
(
gth
(
HasForeignBaseClass
),
{
'some_xrepr'
:
XRepr
,
'other_a'
:
mod_generics_cache
.
A
,
'some_b'
:
mod_generics_cache
.
B
})
self
.
assertEqual
(
gth
(
XRepr
.
__new__
),
{
'x'
:
int
,
'y'
:
int
})
self
.
assertEqual
(
gth
(
mod_generics_cache
.
B
),
{
'my_inner_a1'
:
mod_generics_cache
.
B
.
A
,
'my_inner_a2'
:
mod_generics_cache
.
B
.
A
,
...
...
Lib/typing.py
Dosyayı görüntüle @
43d12a6b
...
...
@@ -607,7 +607,8 @@ class TypeVar(_Final, _Immutable, _root=True):
# * __parameters__ is a tuple of unique free type parameters of a generic
# type, for example, Dict[T, T].__parameters__ == (T,);
# * __origin__ keeps a reference to a type that was subscripted,
# e.g., Union[T, int].__origin__ == Union;
# e.g., Union[T, int].__origin__ == Union, or the non-generic version of
# the type.
# * __args__ is a tuple of all arguments used in subscripting,
# e.g., Dict[T, int].__args__ == (T, int).
...
...
@@ -835,7 +836,11 @@ class Generic:
if
cls
is
Generic
:
raise
TypeError
(
"Type Generic cannot be instantiated; "
"it can be used only as a base class"
)
return
super
()
.
__new__
(
cls
)
if
super
()
.
__new__
is
object
.
__new__
:
obj
=
super
()
.
__new__
(
cls
)
else
:
obj
=
super
()
.
__new__
(
cls
,
*
args
,
**
kwds
)
return
obj
@_tp_cache
def
__class_getitem__
(
cls
,
params
):
...
...
@@ -1385,6 +1390,7 @@ class NamedTupleMeta(type):
"follow default field(s) {default_names}"
.
format
(
field_name
=
field_name
,
default_names
=
', '
.
join
(
defaults_dict
.
keys
())))
nm_tpl
.
__new__
.
__annotations__
=
collections
.
OrderedDict
(
types
)
nm_tpl
.
__new__
.
__defaults__
=
tuple
(
defaults
)
nm_tpl
.
_field_defaults
=
defaults_dict
# update from user namespace without overriding special namedtuple attributes
...
...
Misc/NEWS.d/next/Library/2018-05-08-16-43-42.bpo-28556._xr5mp.rst
0 → 100644
Dosyayı görüntüle @
43d12a6b
Minor fixes in typing module: add annotations to ``NamedTuple.__new__``,
pass ``*args`` and ``**kwds`` in ``Generic.__new__``. Original PRs by
Paulius Šarka and Chad Dombrova.
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