Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feedback from David Foster
  • Loading branch information
JelleZijlstra committed Feb 2, 2022
commit 3b09f1b44e7c9df120b47e701c71a35979779bf6
3 changes: 2 additions & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,8 @@ Functions and decorators
assert_type(name, str) # ok
Comment thread
JelleZijlstra marked this conversation as resolved.
Resolved
assert_type(name, int) # type checker error

At runtime this returns the first argument unchanged.
At runtime this returns the first argument unchanged and otherwise
does nothing.
Comment thread
JelleZijlstra marked this conversation as resolved.
Resolved

Comment thread
JelleZijlstra marked this conversation as resolved.
Resolved
.. versionadded:: 3.11

Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2681,8 +2681,9 @@ def test_basics(self):

def test_errors(self):
# Bogus calls are not expected to fail.
assert_type(42, 42)
assert_type(42, 'hello')
arg = 42
self.assertIs(assert_type(arg, 42), arg)
self.assertIs(assert_type(arg, 'hello'), arg)


class ForwardRefTests(BaseTestCase):
Expand Down
3 changes: 2 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,8 @@ def greet(name: str) -> None:
assert_type(name, str) # ok
assert_type(name, int) # type checker error

At runtime this returns the first argument unchanged.
At runtime this returns the first argument unchanged and otherwise
does nothing.

"""
return val
Expand Down