Skip to content

Commit 7b1be2a

Browse files
miss-islingtonhauntsaninja
authored andcommitted
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 37d1659 commit 7b1be2a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Doc/library/typing.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ A type alias is defined by assigning the type to the alias. In this example,
100100
def scale(scalar: float, vector: Vector) -> Vector:
101101
return [scalar * num for num in vector]
102102

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

106106
Type aliases are useful for simplifying complex type signatures. For example::
@@ -142,10 +142,10 @@ of the original type. This is useful in helping catch logical errors::
142142
def get_user_name(user_id: UserId) -> str:
143143
...
144144

145-
# typechecks
145+
# passes type checking
146146
user_a = get_user_name(UserId(42351))
147147

148-
# does not typecheck; an int is not a UserId
148+
# fails type checking; an int is not a UserId
149149
user_b = get_user_name(-1)
150150

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

172172
UserId = NewType('UserId', int)
173173

174-
# Fails at runtime and does not typecheck
174+
# Fails at runtime and does not pass type checking
175175
class AdminUserId(UserId): pass
176176

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

460460
def foo(item: Any) -> int:
461-
# Typechecks; 'item' could be any type,
461+
# Passes type checking; 'item' could be any type,
462462
# and that type might have a 'bar' method
463463
item.bar()
464464
...
465465

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

497497
def hash_a(item: object) -> int:
498-
# Fails; an object does not have a 'magic' method.
498+
# Fails type checking; an object does not have a 'magic' method.
499499
item.magic()
500500
...
501501

502502
def hash_b(item: Any) -> int:
503-
# Typechecks
503+
# Passes type checking
504504
item.magic()
505505
...
506506

507-
# Typechecks, since ints and strs are subclasses of object
507+
# Passes type checking, since ints and strs are subclasses of object
508508
hash_a(42)
509509
hash_a("foo")
510510

511-
# Typechecks, since Any is compatible with all types
511+
# Passes type checking, since Any is compatible with all types
512512
hash_b(42)
513513
hash_b("foo")
514514

0 commit comments

Comments
 (0)