Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd22c35d

Browse files
gh-96130: Rephrase use of "typecheck" verb for clarity (GH-98144)
I'm sympathetic to the issue report, especially in case this helpsclarify to new users that Python itself does not do type checking at runtime(cherry picked from commited6344e)Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
1 parent9b12084 commitd22c35d

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
@@ -105,7 +105,7 @@ A type alias is defined by assigning the type to the alias. In this example,
105105
def scale(scalar: float, vector: Vector) -> Vector:
106106
return [scalar * num for num in vector]
107107

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

111111
Type aliases are useful for simplifying complex type signatures. For example::
@@ -147,10 +147,10 @@ of the original type. This is useful in helping catch logical errors::
147147
def get_user_name(user_id: UserId) -> str:
148148
...
149149

150-
#typechecks
150+
#passes type checking
151151
user_a = get_user_name(UserId(42351))
152152

153-
#does not typecheck; an int is not a UserId
153+
#fails type checking; an int is not a UserId
154154
user_b = get_user_name(-1)
155155

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

177177
UserId = NewType('UserId', int)
178178

179-
# Fails at runtime and does nottypecheck
179+
# Fails at runtime and does notpass type checking
180180
class AdminUserId(UserId): pass
181181

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

465465
def foo(item: Any) -> int:
466-
#Typechecks; 'item' could be any type,
466+
#Passes type checking; 'item' could be any type,
467467
# and that type might have a 'bar' method
468468
item.bar()
469469
...
470470

471-
Notice that notypechecking is performed when assigning a value of type
471+
Notice that notype checking is performed when assigning a value of type
472472
:data:`Any` to a more precise type. For example, the static type checker did
473473
not report an error when assigning ``a`` to ``s`` even though ``s`` was
474474
declared to be of type:class:`str` and receives an:class:`int` value at
@@ -500,20 +500,20 @@ reject almost all operations on it, and assigning it to a variable (or using
500500
it as a return value) of a more specialized type is a type error. For example::
501501

502502
def hash_a(item: object) -> int:
503-
# Fails; an object does not have a 'magic' method.
503+
# Fails type checking; an object does not have a 'magic' method.
504504
item.magic()
505505
...
506506

507507
def hash_b(item: Any) -> int:
508-
#Typechecks
508+
#Passes type checking
509509
item.magic()
510510
...
511511

512-
#Typechecks, since ints and strs are subclasses of object
512+
#Passes type checking, since ints and strs are subclasses of object
513513
hash_a(42)
514514
hash_a("foo")
515515

516-
#Typechecks, since Any is compatible with all types
516+
#Passes type checking, since Any is compatible with all types
517517
hash_b(42)
518518
hash_b("foo")
519519

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp