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
0e61dffd
Commit
0e61dffd
authored
May 22, 2018
by
Nina Zakharenko
Committed by
Ivan Levkivskyi
May 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverse the meaning of is_argument when used for type check (GH-7039)
parent
8bb0b5b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
4 deletions
+4
-4
Lib/typing.py
Lib/typing.py
+4
-4
No files found.
Lib/typing.py
View file @
0e61dffd
...
...
@@ -106,7 +106,7 @@ __all__ = [
# legitimate imports of those modules.
def
_type_check
(
arg
,
msg
,
is_argument
=
Fals
e
):
def
_type_check
(
arg
,
msg
,
is_argument
=
Tru
e
):
"""Check that the argument is a type, and return it (internal helper).
As a special case, accept None and return type(None) instead. Also wrap strings
...
...
@@ -119,7 +119,7 @@ def _type_check(arg, msg, is_argument=False):
We append the repr() of the actual value (truncated to 100 chars).
"""
invalid_generic_forms
=
(
Generic
,
_Protocol
)
if
not
is_argument
:
if
is_argument
:
invalid_generic_forms
=
invalid_generic_forms
+
(
ClassVar
,
)
if
arg
is
None
:
...
...
@@ -445,7 +445,7 @@ class ForwardRef(_Final, _root=True):
'__forward_evaluated__'
,
'__forward_value__'
,
'__forward_is_argument__'
)
def
__init__
(
self
,
arg
,
is_argument
=
Fals
e
):
def
__init__
(
self
,
arg
,
is_argument
=
Tru
e
):
if
not
isinstance
(
arg
,
str
):
raise
TypeError
(
f"Forward reference must be a string -- got
{
arg
!
r
}
"
)
try
:
...
...
@@ -979,7 +979,7 @@ def get_type_hints(obj, globalns=None, localns=None):
if
value
is
None
:
value
=
type
(
None
)
if
isinstance
(
value
,
str
):
value
=
ForwardRef
(
value
,
is_argument
=
Tru
e
)
value
=
ForwardRef
(
value
,
is_argument
=
Fals
e
)
value
=
_eval_type
(
value
,
base_globals
,
localns
)
hints
[
name
]
=
value
return
hints
...
...
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