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
95919c09
Kaydet (Commit)
95919c09
authored
Ock 23, 2017
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28556: Allow defining methods in NamedTuple class syntax (#362)
üst
d7adfe12
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
5 deletions
+31
-5
test_typing.py
Lib/test/test_typing.py
+27
-5
typing.py
Lib/typing.py
+4
-0
No files found.
Lib/test/test_typing.py
Dosyayı görüntüle @
95919c09
...
...
@@ -612,8 +612,10 @@ class GenericTests(BaseTestCase):
self
.
assertEqual
(
repr
(
typing
.
Mapping
[
T
,
TS
][
TS
,
T
]),
'typing.Mapping[~TS, ~T]'
)
self
.
assertEqual
(
repr
(
List
[
Tuple
[
T
,
TS
]][
int
,
T
]),
'typing.List[typing.Tuple[int, ~T]]'
)
self
.
assertEqual
(
repr
(
List
[
Tuple
[
T
,
T
]][
List
[
int
]]),
'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]'
)
self
.
assertEqual
(
repr
(
List
[
Tuple
[
T
,
T
]][
List
[
int
]]),
'typing.List[typing.Tuple[typing.List[int], typing.List[int]]]'
)
def
test_new_repr_bare
(
self
):
T
=
TypeVar
(
'T'
)
...
...
@@ -684,8 +686,10 @@ class GenericTests(BaseTestCase):
raise
NotImplementedError
if
tp
.
__args__
:
KT
,
VT
=
tp
.
__args__
return
all
(
isinstance
(
k
,
KT
)
and
isinstance
(
v
,
VT
)
for
k
,
v
in
obj
.
items
())
return
all
(
isinstance
(
k
,
KT
)
and
isinstance
(
v
,
VT
)
for
k
,
v
in
obj
.
items
()
)
self
.
assertTrue
(
naive_dict_check
({
'x'
:
1
},
typing
.
Dict
[
str
,
int
]))
self
.
assertFalse
(
naive_dict_check
({
1
:
'x'
},
typing
.
Dict
[
str
,
int
]))
with
self
.
assertRaises
(
NotImplementedError
):
...
...
@@ -1409,6 +1413,16 @@ class CoolEmployee(NamedTuple):
class CoolEmployeeWithDefault(NamedTuple):
name: str
cool: int = 0
class XMeth(NamedTuple):
x: int
def double(self):
return 2 * self.x
class XMethBad(NamedTuple):
x: int
def _fields(self):
return 'no chance for this'
"""
if
PY36
:
...
...
@@ -1417,6 +1431,7 @@ else:
# fake names for the sake of static analysis
ann_module
=
ann_module2
=
ann_module3
=
None
A
=
B
=
CSub
=
G
=
CoolEmployee
=
CoolEmployeeWithDefault
=
object
XMeth
=
XMethBad
=
object
gth
=
get_type_hints
...
...
@@ -1750,7 +1765,7 @@ class CollectionsAbcTests(BaseTestCase):
def
test_async_generator
(
self
):
ns
=
{}
exec
(
"async def f():
\n
"
" yield 42
\n
"
,
globals
(),
ns
)
" yield 42
\n
"
,
globals
(),
ns
)
g
=
ns
[
'f'
]()
self
.
assertIsSubclass
(
type
(
g
),
typing
.
AsyncGenerator
)
...
...
@@ -2038,6 +2053,13 @@ class NonDefaultAfterDefault(NamedTuple):
y: int
"""
)
@skipUnless
(
PY36
,
'Python 3.6 required'
)
def
test_annotation_usage_with_methods
(
self
):
self
.
assertEquals
(
XMeth
(
1
)
.
double
(),
2
)
self
.
assertEquals
(
XMeth
(
42
)
.
x
,
XMeth
(
42
)[
0
])
self
.
assertEquals
(
XMethBad
(
1
)
.
_fields
,
(
'x'
,))
self
.
assertEquals
(
XMethBad
(
1
)
.
__annotations__
,
{
'x'
:
int
})
@skipUnless
(
PY36
,
'Python 3.6 required'
)
def
test_namedtuple_keyword_usage
(
self
):
LocalEmployee
=
NamedTuple
(
"LocalEmployee"
,
name
=
str
,
age
=
int
)
...
...
Lib/typing.py
Dosyayı görüntüle @
95919c09
...
...
@@ -2000,6 +2000,10 @@ class NamedTupleMeta(type):
default_names
=
', '
.
join
(
defaults_dict
.
keys
())))
nm_tpl
.
__new__
.
__defaults__
=
tuple
(
defaults
)
nm_tpl
.
_field_defaults
=
defaults_dict
# update from user namespace without overriding special namedtuple attributes
for
key
in
ns
:
if
not
hasattr
(
nm_tpl
,
key
):
setattr
(
nm_tpl
,
key
,
ns
[
key
])
return
nm_tpl
...
...
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