-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No type checking for thread local variables? #2388
Comments
The former is blocked by #521 (it even says so in the stub for threading.local). The latter would be a pretty advanced feature -- while PEP 526 allows this syntax it doesn't mandate that type checkers should support it. But IIRC you can subclass threading.local and then you can use annotations in the class definition. |
I don't see how we can sensibly assign a type to the result of Within a module, you could adopt something like the following style. import threading
_parameter_values = threading.local()
local_data: Dict[int, str] = {}
_parameter_values.data = local_data
local_data[3] = "hello" and then only access |
But see the docstring of _threading_local.py (which apparently is the only reference, the official docs for threading.oocal point there):
|
I'd love the latter. Not so much for thread-local variables, rather to allow 3rd party library extensions, like pyropy/fastapi-socketio#27 Or, perhaps, what I'm thinking of could be done in some other way? |
The following type checks without errors even though I am running with "--disallow-untyped-defs --disallow-untyped-calls".
and if I deliberately try to add annotations:
then I get the following error:
error: Type cannot be declared in assignment to non-self attribute
The text was updated successfully, but these errors were encountered: