mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] Miscellaneous improvements to the typing docs (GH-105529) (#105567)
Miscellaneous improvements to the typing docs (GH-105529)
Mostly, these are changes so that we use shorter sentences and shorter paragraphs. In particular, I've tried to make the first sentence introducing each object in the typing API short and declarative.
(cherry picked from commit 8e755923c9
)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
d29e86bea3
commit
7c298d2dc5
3 changed files with 229 additions and 145 deletions
|
@ -567,7 +567,7 @@ def Never(self, parameters):
|
|||
case str():
|
||||
print("It's a str")
|
||||
case _:
|
||||
never_call_me(arg) # ok, arg is of type Never
|
||||
never_call_me(arg) # OK, arg is of type Never
|
||||
"""
|
||||
raise TypeError(f"{self} is not subscriptable")
|
||||
|
||||
|
@ -600,13 +600,13 @@ def LiteralString(self, parameters):
|
|||
|
||||
from typing import LiteralString
|
||||
|
||||
def run_query(sql: LiteralString) -> ...
|
||||
def run_query(sql: LiteralString) -> None:
|
||||
...
|
||||
|
||||
def caller(arbitrary_string: str, literal_string: LiteralString) -> None:
|
||||
run_query("SELECT * FROM students") # ok
|
||||
run_query(literal_string) # ok
|
||||
run_query("SELECT * FROM " + literal_string) # ok
|
||||
run_query("SELECT * FROM students") # OK
|
||||
run_query(literal_string) # OK
|
||||
run_query("SELECT * FROM " + literal_string) # OK
|
||||
run_query(arbitrary_string) # type checker error
|
||||
run_query( # type checker error
|
||||
f"SELECT * FROM students WHERE name = {arbitrary_string}"
|
||||
|
@ -2124,7 +2124,7 @@ def assert_type(val, typ, /):
|
|||
emits an error if the value is not of the specified type::
|
||||
|
||||
def greet(name: str) -> None:
|
||||
assert_type(name, str) # ok
|
||||
assert_type(name, str) # OK
|
||||
assert_type(name, int) # type checker error
|
||||
"""
|
||||
return val
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue