@@ -105,7 +105,7 @@ A type alias is defined by assigning the type to the alias. In this example,
105
105
def scale(scalar: float, vector: Vector) -> Vector:
106
106
return [scalar * num for num in vector]
107
107
108
- # typechecks ; a list of floats qualifies as a Vector.
108
+ # passes type checking ; a list of floats qualifies as a Vector.
109
109
new_vector = scale(2.0, [1.0, -4.2, 5.4])
110
110
111
111
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::
147
147
def get_user_name(user_id: UserId) -> str:
148
148
...
149
149
150
- # typechecks
150
+ # passes type checking
151
151
user_a = get_user_name(UserId(42351))
152
152
153
- # does not typecheck ; an int is not a UserId
153
+ # fails type checking ; an int is not a UserId
154
154
user_b = get_user_name(-1)
155
155
156
156
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``::
176
176
177
177
UserId = NewType('UserId', int)
178
178
179
- # Fails at runtime and does not typecheck
179
+ # Fails at runtime and does not pass type checking
180
180
class AdminUserId(UserId): pass
181
181
182
182
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::
463
463
s = a # OK
464
464
465
465
def foo(item: Any) -> int:
466
- # Typechecks ; 'item' could be any type,
466
+ # Passes type checking ; 'item' could be any type,
467
467
# and that type might have a 'bar' method
468
468
item.bar()
469
469
...
470
470
471
- Notice that no typechecking is performed when assigning a value of type
471
+ Notice that no type checking is performed when assigning a value of type
472
472
:data: `Any ` to a more precise type. For example, the static type checker did
473
473
not report an error when assigning ``a `` to ``s `` even though ``s `` was
474
474
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
500
500
it as a return value) of a more specialized type is a type error. For example::
501
501
502
502
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.
504
504
item.magic()
505
505
...
506
506
507
507
def hash_b(item: Any) -> int:
508
- # Typechecks
508
+ # Passes type checking
509
509
item.magic()
510
510
...
511
511
512
- # Typechecks , since ints and strs are subclasses of object
512
+ # Passes type checking , since ints and strs are subclasses of object
513
513
hash_a(42)
514
514
hash_a("foo")
515
515
516
- # Typechecks , since Any is compatible with all types
516
+ # Passes type checking , since Any is compatible with all types
517
517
hash_b(42)
518
518
hash_b("foo")
519
519
0 commit comments