diff --git a/docs/spec/annotations.rst b/docs/spec/annotations.rst index 17eae5b9f..a3b8ea7df 100644 --- a/docs/spec/annotations.rst +++ b/docs/spec/annotations.rst @@ -42,7 +42,7 @@ have a return annotation; the default behavior is thus the same as for other methods.) A type checker is expected to check the body of a checked function for -consistency with the given annotations. The annotations may also be +consistency with the given annotations. The annotations may also be used to check correctness of calls appearing in other checked functions. Type checkers are expected to attempt to infer as much information as diff --git a/docs/spec/callables.rst b/docs/spec/callables.rst index 072c4a0fc..382c9ded3 100644 --- a/docs/spec/callables.rst +++ b/docs/spec/callables.rst @@ -154,7 +154,7 @@ compatible:: class Animal(TypedDict): name: str - + class Dog(Animal): breed: str @@ -181,10 +181,10 @@ function arguments. Again, the rest of the parameters have to be compatible. Continuing the previous example:: class Example(TypedDict): - animal: Animal + animal: Animal string: str number: NotRequired[int] - + def src(**kwargs: Unpack[Example]): ... def dest(*, animal: Dog, string: str, number: int = ...): ... @@ -245,7 +245,7 @@ type ``T``:: class Vehicle: ... - + class Car(Vehicle): ... @@ -255,7 +255,7 @@ type ``T``:: class Vehicles(TypedDict): car: Car moto: Motorcycle - + def dest(**kwargs: Unpack[Vehicles]): ... def src(**kwargs: Vehicle): ... @@ -279,7 +279,7 @@ consider the following example:: class Animal(TypedDict): name: str - + class Dog(Animal): breed: str @@ -290,21 +290,21 @@ consider the following example:: def foo(**kwargs: Unpack[Animal]): print(kwargs["name"].capitalize()) - + def bar(**kwargs: Unpack[Animal]): takes_name(**kwargs) - + def baz(animal: Animal): takes_name(**animal) - + def spam(**kwargs: Unpack[Animal]): baz(kwargs) - + foo(**animal) # OK! foo only expects and uses keywords of 'Animal'. bar(**animal) # WRONG! This will fail at runtime because 'breed' keyword # will be passed to 'takes_name' as well. - + spam(**animal) # WRONG! Again, 'breed' keyword will be eventually passed # to 'takes_name'. diff --git a/docs/spec/generics.rst b/docs/spec/generics.rst index 0878663e7..fa9947520 100644 --- a/docs/spec/generics.rst +++ b/docs/spec/generics.rst @@ -1050,7 +1050,7 @@ Or when using the built-in syntax for generics in Python 3.12 and higher:: class Array[*Ts]: ... - + def foo[*Ts](*args: *Ts): ... @@ -1685,7 +1685,7 @@ to the ``TypeVarTuple``: Ptang[str, bool, float] # T1=str, T3=float, T2=bool, Ts=tuple[()] Ptang[str, bool, float, int] # T1=str, T3=int, T2=float, Ts=tuple[bool] - + Note that the minimum number of type arguments in such cases is set by the number of ``TypeVar``\s: @@ -2406,7 +2406,7 @@ Here is an example. class ClassA[T1, T2, T3](list[T1]): def method1(self, a: T2) -> None: ... - + def method2(self) -> T3: ... diff --git a/docs/spec/historical.rst b/docs/spec/historical.rst index b505fc327..e586c7987 100644 --- a/docs/spec/historical.rst +++ b/docs/spec/historical.rst @@ -26,7 +26,7 @@ complex cases, a comment of the following format may be used:: x = [1, 2] # type: list[int] Type comments should be put on the last line of the statement that -contains the variable definition. +contains the variable definition. These should be treated as equivalent to annotating the variables using :pep:`526` variable annotations:: diff --git a/docs/spec/literal.rst b/docs/spec/literal.rst index 9f800b704..39d214f38 100644 --- a/docs/spec/literal.rst +++ b/docs/spec/literal.rst @@ -192,7 +192,7 @@ allowing them in the future. - Floats: e.g. ``Literal[3.14]``. Representing Literals of infinity or NaN in a clean way is tricky; real-world APIs are unlikely to vary their behavior based on a float parameter. - + - Any: e.g. ``Literal[Any]``. ``Any`` is a type, and ``Literal[...]`` is meant to contain values only. It is also unclear what ``Literal[Any]`` would actually semantically mean. @@ -515,7 +515,7 @@ involving Literal bools. For example, we can combine ``Literal[True]``, scalar += 3 # Type checks: type of 'scalar' is narrowed to 'int' else: scalar += "foo" # Type checks: type of 'scalar' is narrowed to 'str' - + Interactions with Final """"""""""""""""""""""" diff --git a/docs/spec/narrowing.rst b/docs/spec/narrowing.rst index 91b9e00bb..a30b91b13 100644 --- a/docs/spec/narrowing.rst +++ b/docs/spec/narrowing.rst @@ -74,9 +74,9 @@ allows for cases like the example above where ``list[str]`` is not assignable to ``list[object]``. When a conditional statement includes a call to a user-defined type guard -function, and that function returns true, the expression passed as the first -positional argument to the type guard function should be assumed by a static -type checker to take on the type specified in the TypeGuard return type, +function, and that function returns true, the expression passed as the first +positional argument to the type guard function should be assumed by a static +type checker to take on the type specified in the TypeGuard return type, unless and until it is further narrowed within the conditional code block. Some built-in type guards provide narrowing for both positive and negative @@ -97,7 +97,7 @@ is not narrowed in the negative case. else: reveal_type(val) # OneOrTwoStrs ... - + if not is_two_element_tuple(val): reveal_type(val) # OneOrTwoStrs ... diff --git a/docs/spec/requirements.txt b/docs/spec/requirements.txt deleted file mode 100644 index 3ef203c86..000000000 --- a/docs/spec/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -sphinx -furo