@@ -91,7 +91,7 @@ A type alias is defined by assigning the type to the alias. In this example,
91
91
def scale(scalar: float, vector: Vector) -> Vector:
92
92
return [scalar * num for num in vector]
93
93
94
- # typechecks ; a list of floats qualifies as a Vector.
94
+ # passes type checking ; a list of floats qualifies as a Vector.
95
95
new_vector = scale(2.0, [1.0, -4.2, 5.4])
96
96
97
97
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::
133
133
def get_user_name(user_id: UserId) -> str:
134
134
...
135
135
136
- # typechecks
136
+ # passes type checking
137
137
user_a = get_user_name(UserId(42351))
138
138
139
- # does not typecheck ; an int is not a UserId
139
+ # fails type checking ; an int is not a UserId
140
140
user_b = get_user_name(-1)
141
141
142
142
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``::
162
162
163
163
UserId = NewType('UserId', int)
164
164
165
- # Fails at runtime and does not typecheck
165
+ # Fails at runtime and does not pass type checking
166
166
class AdminUserId(UserId): pass
167
167
168
168
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::
449
449
s = a # OK
450
450
451
451
def foo(item: Any) -> int:
452
- # Typechecks ; 'item' could be any type,
452
+ # Passes type checking ; 'item' could be any type,
453
453
# and that type might have a 'bar' method
454
454
item.bar()
455
455
...
456
456
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
458
458
:data: `Any ` to a more precise type. For example, the static type checker did
459
459
not report an error when assigning ``a `` to ``s `` even though ``s `` was
460
460
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
486
486
it as a return value) of a more specialized type is a type error. For example::
487
487
488
488
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.
490
490
item.magic()
491
491
...
492
492
493
493
def hash_b(item: Any) -> int:
494
- # Typechecks
494
+ # Passes type checking
495
495
item.magic()
496
496
...
497
497
498
- # Typechecks , since ints and strs are subclasses of object
498
+ # Passes type checking , since ints and strs are subclasses of object
499
499
hash_a(42)
500
500
hash_a("foo")
501
501
502
- # Typechecks , since Any is compatible with all types
502
+ # Passes type checking , since Any is compatible with all types
503
503
hash_b(42)
504
504
hash_b("foo")
505
505
0 commit comments