Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5cb8ae34
Commit
5cb8ae34
authored
Nov 19, 2016
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28556: two more small upstream changes by Ivan Levkivskyi (#329, #330)
parent
dd656e4e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
Lib/test/test_typing.py
Lib/test/test_typing.py
+19
-2
Lib/typing.py
Lib/typing.py
+2
-0
No files found.
Lib/test/test_typing.py
View file @
5cb8ae34
...
...
@@ -45,6 +45,10 @@ class BaseTestCase(TestCase):
message
+=
' : %s'
%
msg
raise
self
.
failureException
(
message
)
def
clear_caches
(
self
):
for
f
in
typing
.
_cleanups
:
f
()
class
Employee
:
pass
...
...
@@ -509,6 +513,13 @@ class ProtocolTests(BaseTestCase):
def
test_protocol_instance_type_error
(
self
):
with
self
.
assertRaises
(
TypeError
):
isinstance
(
0
,
typing
.
SupportsAbs
)
class
C1
(
typing
.
SupportsInt
):
def
__int__
(
self
)
->
int
:
return
42
class
C2
(
C1
):
pass
c
=
C2
()
self
.
assertIsInstance
(
c
,
C1
)
class
GenericTests
(
BaseTestCase
):
...
...
@@ -748,8 +759,12 @@ class GenericTests(BaseTestCase):
class
CC
:
...
self
.
assertEqual
(
get_type_hints
(
foobar
,
globals
(),
locals
()),
{
'x'
:
List
[
List
[
CC
]]})
T
=
TypeVar
(
'T'
)
def
barfoo
(
x
:
Tuple
[
T
,
...]):
...
self
.
assertIs
(
get_type_hints
(
barfoo
,
globals
(),
locals
())[
'x'
],
Tuple
[
T
,
...])
AT
=
Tuple
[
T
,
...]
def
barfoo
(
x
:
AT
):
...
self
.
assertIs
(
get_type_hints
(
barfoo
,
globals
(),
locals
())[
'x'
],
AT
)
CT
=
Callable
[...,
List
[
T
]]
def
barfoo2
(
x
:
CT
):
...
self
.
assertIs
(
get_type_hints
(
barfoo2
,
globals
(),
locals
())[
'x'
],
CT
)
def
test_extended_generic_rules_subclassing
(
self
):
class
T1
(
Tuple
[
T
,
KT
]):
...
...
...
@@ -800,6 +815,8 @@ class GenericTests(BaseTestCase):
def
test_type_erasure_special
(
self
):
T
=
TypeVar
(
'T'
)
# this is the only test that checks type caching
self
.
clear_caches
()
class
MyTup
(
Tuple
[
T
,
T
]):
...
self
.
assertIs
(
MyTup
[
int
]().
__class__
,
MyTup
)
self
.
assertIs
(
MyTup
[
int
]().
__orig_class__
,
MyTup
[
int
])
...
...
Lib/typing.py
View file @
5cb8ae34
...
...
@@ -1503,6 +1503,8 @@ class _ProtocolMeta(GenericMeta):
"""
def
__instancecheck__
(
self
,
obj
):
if
_Protocol
not
in
self
.
__bases__
:
return
super
().
__instancecheck__
(
obj
)
raise
TypeError
(
"Protocols cannot be used with isinstance()."
)
def
__subclasscheck__
(
self
,
cls
):
...
...
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