PEP 692: Small fixes (#3173)
This commit is contained in:
parent
1b0666eafa
commit
03cbb75ef4
18
pep-0692.rst
18
pep-0692.rst
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue