@@ -100,7 +100,7 @@ A type alias is defined by assigning the type to the alias. In this example,
100
100
def scale(scalar: float, vector: Vector) -> Vector:
101
101
return [scalar * num for num in vector]
102
102
103
- # typechecks ; a list of floats qualifies as a Vector.
103
+ # passes type checking ; a list of floats qualifies as a Vector.
104
104
new_vector = scale(2.0, [1.0, -4.2, 5.4])
105
105
106
106
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::
142
142
def get_user_name(user_id: UserId) -> str:
143
143
...
144
144
145
- # typechecks
145
+ # passes type checking
146
146
user_a = get_user_name(UserId(42351))
147
147
148
- # does not typecheck ; an int is not a UserId
148
+ # fails type checking ; an int is not a UserId
149
149
user_b = get_user_name(-1)
150
150
151
151
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``::
171
171
172
172
UserId = NewType('UserId', int)
173
173
174
- # Fails at runtime and does not typecheck
174
+ # Fails at runtime and does not pass type checking
175
175
class AdminUserId(UserId): pass
176
176
177
177
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::
458
458
s = a # OK
459
459
460
460
def foo(item: Any) -> int:
461
- # Typechecks ; 'item' could be any type,
461
+ # Passes type checking ; 'item' could be any type,
462
462
# and that type might have a 'bar' method
463
463
item.bar()
464
464
...
465
465
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
467
467
:data: `Any ` to a more precise type. For example, the static type checker did
468
468
not report an error when assigning ``a `` to ``s `` even though ``s `` was
469
469
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
495
495
it as a return value) of a more specialized type is a type error. For example::
496
496
497
497
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.
499
499
item.magic()
500
500
...
501
501
502
502
def hash_b(item: Any) -> int:
503
- # Typechecks
503
+ # Passes type checking
504
504
item.magic()
505
505
...
506
506
507
- # Typechecks , since ints and strs are subclasses of object
507
+ # Passes type checking , since ints and strs are subclasses of object
508
508
hash_a(42)
509
509
hash_a("foo")
510
510
511
- # Typechecks , since Any is compatible with all types
511
+ # Passes type checking , since Any is compatible with all types
512
512
hash_b(42)
513
513
hash_b("foo")
514
514
0 commit comments