Skip to content

Commit 48447d4

Browse files
gh-96130: Rephrase use of "typecheck" verb for clarity (GH-98144)
I'm sympathetic to the issue report, especially in case this helps clarify to new users that Python itself does not do type checking at runtime (cherry picked from commit ed6344e) Co-authored-by: Shantanu <[email protected]>
1 parent af63fa0 commit 48447d4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Doc/library/typing.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ A type alias is defined by assigning the type to the alias. In this example,
9191
def scale(scalar: float, vector: Vector) -> Vector:
9292
return [scalar * num for num in vector]
9393

94-
# typechecks; a list of floats qualifies as a Vector.
94+
# passes type checking; a list of floats qualifies as a Vector.
9595
new_vector = scale(2.0, [1.0, -4.2, 5.4])
9696

9797
Type aliases are useful for simplifying complex type signatures. For example::
@@ -133,10 +133,10 @@ of the original type. This is useful in helping catch logical errors::
133133
def get_user_name(user_id: UserId) -> str:
134134
...
135135

136-
# typechecks
136+
# passes type checking
137137
user_a = get_user_name(UserId(42351))
138138

139-
# does not typecheck; an int is not a UserId
139+
# fails type checking; an int is not a UserId
140140
user_b = get_user_name(-1)
141141

142142
You may still perform all ``int`` operations on a variable of type ``UserId``,
@@ -162,7 +162,7 @@ It is invalid to create a subtype of ``Derived``::
162162

163163
UserId = NewType('UserId', int)
164164

165-
# Fails at runtime and does not typecheck
165+
# Fails at runtime and does not pass type checking
166166
class AdminUserId(UserId): pass
167167

168168
However, it is possible to create a :class:`NewType` based on a 'derived' ``NewType``::
@@ -449,12 +449,12 @@ value of type :data:`Any` and assign it to any variable::
449449
s = a # OK
450450

451451
def foo(item: Any) -> int:
452-
# Typechecks; 'item' could be any type,
452+
# Passes type checking; 'item' could be any type,
453453
# and that type might have a 'bar' method
454454
item.bar()
455455
...
456456

457-
Notice that no typechecking is performed when assigning a value of type
457+
Notice that no type checking is performed when assigning a value of type
458458
:data:`Any` to a more precise type. For example, the static type checker did
459459
not report an error when assigning ``a`` to ``s`` even though ``s`` was
460460
declared to be of type :class:`str` and receives an :class:`int` value at
@@ -486,20 +486,20 @@ reject almost all operations on it, and assigning it to a variable (or using
486486
it as a return value) of a more specialized type is a type error. For example::
487487

488488
def hash_a(item: object) -> int:
489-
# Fails; an object does not have a 'magic' method.
489+
# Fails type checking; an object does not have a 'magic' method.
490490
item.magic()
491491
...
492492

493493
def hash_b(item: Any) -> int:
494-
# Typechecks
494+
# Passes type checking
495495
item.magic()
496496
...
497497

498-
# Typechecks, since ints and strs are subclasses of object
498+
# Passes type checking, since ints and strs are subclasses of object
499499
hash_a(42)
500500
hash_a("foo")
501501

502-
# Typechecks, since Any is compatible with all types
502+
# Passes type checking, since Any is compatible with all types
503503
hash_b(42)
504504
hash_b("foo")
505505

0 commit comments

Comments
 (0)