mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Miscellaneous improvements to the typing docs (#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.
This commit is contained in:
parent
b8fa7bda4f
commit
8e755923c9
3 changed files with 229 additions and 145 deletions
|
@ -561,7 +561,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")
|
||||
|
||||
|
@ -594,13 +594,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}"
|
||||
|
@ -2118,7 +2118,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