PEP 692: Small fixes (#3173)

This commit is contained in:
Franek Magiera 2023-06-15 05:48:13 +02:00 committed by GitHub
parent 1b0666eafa
commit 03cbb75ef4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 7 deletions

View File

@ -123,7 +123,7 @@ would mean that the ``**kwargs`` comprise two keyword arguments specified by
``Movie`` (i.e. a ``name`` keyword of type ``str`` and a ``year`` keyword of
type ``int``). This indicates that the function should be called as follows::
kwargs: Movie = {name: "Life of Brian", year: 1979}
kwargs: Movie = {"name": "Life of Brian", "year": 1979}
foo(**kwargs) # OK!
foo(name="The Meaning of Life", year=1983) # OK!
@ -251,12 +251,16 @@ It is worth pointing out that the destination function's parameters that are to
be compatible with the keys and values from the ``TypedDict`` must be keyword
only::
def dest(animal: Dog, string: str, number: int = ...): ...
dest(animal_instance, "some string") # OK!
dest = src
dest(animal_instance, "some string") # WRONG! The same call fails at
# runtime now because 'src' expects
# keyword arguments.
def dest(dog: Dog, string: str, number: int = ...): ...
dog: Dog = {"name": "Daisy", "breed": "labrador"}
dest(dog, "some string") # OK!
dest = src # Type checker error!
dest(dog, "some string") # The same call fails at
# runtime now because 'src' expects
# keyword arguments.
The reverse situation where the destination callable contains
``**kwargs: Unpack[TypedDict]`` and the source callable doesn't contain