Comments (9)
I've opened a discussion to see if there's anything we can do in the future:
python/typing#1543
from aiohttp.
The key is the instance, not the name/type.
So, you need to save the key somewhere globally and reuse it across the project.
from aiohttp.
We can probably make this clearer in the docs, but you'll see all the examples use a variable, rather than creating a new instance when indexing.
from aiohttp.
Thank you for the answer, but what is supposed to do when the handlers are defined in a different module than the server initialization?
Should the "standard" define all the app keys in a module and import them both in the module that initiates the server and in the handlers modules?
from aiohttp.
Yes, there needs to be a canonical location. For projects, I typically put them in typedefs.py or similar (along with typing aliases etc.). Between different projects, it needs to be imported, for example see aiohttp-jinja2:
The static function has similar usage, except it requires you to set app[aiohttp_jinja2.static_root_key].
app = web.Application() app[aiohttp_jinja2.static_root_key] = "/static"
https://aiohttp-jinja2.readthedocs.io/en/latest/#default-globals
And we use that key, for example, in aiohttp-devtools:
https://github.com/aio-libs/aiohttp-devtools/blob/master/aiohttp_devtools/runserver/serve.py#L28
from aiohttp.
Ok, I will do it, thank you so much for the fast answer!
from aiohttp.
Hey @Dreamsorcerer, I was making this migration but there are some cases where the value that I want to store an AppKey is a callable (for instance a partial that is completed with the remaining args in the handler). However when I do:
some_key = AppKey("some_key", Callable[[type_arg1, type_arg2], return_type])
Mypy is not very happy saying:
error: Argument 2 to "AppKey" has incompatible type "object"; expected "type[Never] | None"
from aiohttp.
See the examples in the docs for the alternative syntax. i.e. It'll work with AppKey[Callable]("some_key")
. The problem is that things like Callable are not types, but we don't want to annotate it as allowing anything and have mistakes like AppKey(..., 5)
. I'm not sure if there is a better annotation to make this work.
from aiohttp.
Thanks!
from aiohttp.
Related Issues (20)
- `FileResponse` has undefined behavior if the file is changed out from under it between the `stat` and `open` calls
- ClientSession timeout AttributeError
- Addition of 'loop' Parameter Description in web.run_app Documentation HOT 6
- Cannot build wheels for aiohttp HOT 1
- Form-encoded data with None as the value gets passed as string "None" HOT 5
- CVE-2023-49081/2 fix question HOT 12
- Wrong constructor called HOT 3
- Make a protocol ValueError subclass ClientError HOT 2
- Serve static Brotli compressed files
- HTTPS requests received on HTTP port show generic BadStatusLine exception HOT 1
- aiohttp may respond to requests sent after the client asks for the connection to be closed
- ValueError: verify_ssl, ssl_context, fingerprint and ssl parameters are mutually exclusive HOT 2
- Accept-Encoding header parsing and interpretation HOT 15
- Varying node versions & not using NPM clean install
- aiodns can probably be enabled on windows, now that it ships with c-ares already built HOT 3
- Failure introduced from 3.8.5 --> 3.8.6; Passing on 3.9+ HOT 4
- Detailed TimeoutError message not captured when handling asyncio.TimeoutError in aiohttp HOT 8
- after upgrading from 3.8.6 to 3.9.* can't use middlewares anymore HOT 3
- Abrupt client websocket connection loss results in `close_code = OK` HOT 2
- Python package aiohttp>=3.9.2 break azure-keyvault-certificates package's get_certificate functionality HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp.