Mypy 1.8.0 Documentationat runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 1.9 Protocols and structural subtyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . function must accept specifically a list – it would run just fine if you were to pass in a tuple, a set, or any other custom iterable. You can express this idea using collections.abc.Iterable: from collections For collections on Python 3.9+, the type of the collection item is in brackets x: list[int] = [1] x: set[int] = {6, 7} # For mappings, we need the types of both keys and values x: dict[str, float] = {"field":0 码力 | 234 页 | 902.89 KB | 1 年前3
Mypy 1.10.0+dev Documentationmodule Protocols and structural subtyping Predefined protocols Simple user-defined protocols Defining subprotocols and subclassing protocols Invariance of protocol attributes Recursive protocols Using Using isinstance() with protocols Callback protocols Predefined protocol reference Dynamically typed code Operations on Any values Any vs. object Type narrowing Type narrowing expressions Casts User-Defined variables with upper bounds Type variables with value restriction Declaring decorators Generic protocols Generic type aliases Generic class internals More types The NoReturn type NewTypes Function overloading0 码力 | 318 页 | 270.84 KB | 1 年前3
Mypy 1.8.0 Documentationmodule Protocols and structural subtyping Predefined protocols Simple user-defined protocols Defining subprotocols and subclassing protocols Invariance of protocol attributes Recursive protocols Using Using isinstance() with protocols Callback protocols Predefined protocol reference Dynamically typed code Operations on Any values Any vs. object Type narrowing Type narrowing expressions Casts User-Defined variables with upper bounds Type variables with value restriction Declaring decorators Generic protocols Generic type aliases Generic class internals More types The NoReturn type NewTypes Function overloading0 码力 | 318 页 | 271.55 KB | 1 年前3
Mypy 1.10.0+dev Documentationat runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 1.9 Protocols and structural subtyping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . function must accept specifically a list – it would run just fine if you were to pass in a tuple, a set, or any other custom iterable. You can express this idea using collections.abc.Iterable: from collections For collections on Python 3.9+, the type of the collection item is in brackets x: list[int] = [1] x: set[int] = {6, 7} # For mappings, we need the types of both keys and values x: dict[str, float] = {"field":0 码力 | 234 页 | 913.89 KB | 1 年前3
Tornado 5.1 Documentation
which serve as the building blocks for the HTTP components and can also be used to implement other protocols. • A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine0 码力 | 243 页 | 895.80 KB | 1 年前3
Tornado 4.5 Documentation
which serve as the building blocks for the HTTP components and can also be used to implement other protocols. A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward fetch_future = http_client.fetch(url) fetch_future.add_done_callback( lambda f: my_future.set_result(f.result())) return my_future The raw Future version is more complex, but Futures are nonetheless Tornado because they have two major advantages. Error handling is more consistent since the Future.result method can simply raise an exception (as opposed to the ad-hoc error handling common in callback-oriented0 码力 | 333 页 | 322.34 KB | 1 年前3
Tornado 5.1 Documentation
which serve as the building blocks for the HTTP components and can also be used to implement other protocols. A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine0 码力 | 359 页 | 347.32 KB | 1 年前3
Tornado 6.0 Documentation
compatible with Tornado. Applications that use Tornado on Windows with Python 3.8 must call asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) at the beginning of their main file/function which serve as the building blocks for the HTTP components and can also be used to implement other protocols. A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado0 码力 | 869 页 | 692.83 KB | 1 年前3
Tornado 4.5 Documentation
which serve as the building blocks for the HTTP components and can also be used to implement other protocols. • A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward fetch_future = http_client.fetch(url) fetch_future.add_done_callback( lambda f: my_future.set_result(f.result())) return my_future The raw Future version is more complex, but Futures are nonetheless Tornado because they have two major advantages. Error handling is more consistent since the Future.result method can simply raise an exception (as opposed to the ad-hoc error handling common in callback-oriented0 码力 | 222 页 | 833.04 KB | 1 年前3
Tornado 6.1 Documentation
which serve as the building blocks for the HTTP components and can also be used to implement other protocols. • A coroutine library (tornado.gen) which allows asynchronous code to be written in a more straightforward low-level components like the IOLoop that use callbacks. Futures are usually transformed into their result with the await or yield keywords. Examples Here is a sample synchronous function: from tornado AsyncHTTPClient() my_future = Future() fetch_future = http_client.fetch(url) def on_fetch(f): my_future.set_result(f.result().body) fetch_future.add_done_callback(on_fetch) return my_future Notice that the coroutine0 码力 | 245 页 | 904.24 KB | 1 年前3
共 538 条
- 1
- 2
- 3
- 4
- 5
- 6
- 54













