-
Notifications
You must be signed in to change notification settings - Fork 242
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
advanced SimpleNamespace typing #688
Comments
I think |
as far as I can tell, protocols can be used to cast the simple namespace into, but it won't help me typechecking |
Almost, but not completely. IIUC auto-generated |
thanks @ilevkivskyi can you link to related resources about it? |
We don't have a "centralized" issues to track this, but you can watch python/mypy#7856 and/or python/mypy#7790 |
I expect this to work: from typing import Protocol
from types import SimpleNamespace
class Person(Protocol):
@property
def name(self) -> str: ...
@property
def age(self) -> int: ...
def get_person() -> Person:
return SimpleNamespace(
name="Alice",
age=40
) But I am not getting any type checking whatsoever. |
I use def returns_namespace() -> SimpleNamespace[int]:
return SimpleNamespace(a=1, b=2) This is not possible at the moment as |
That should be |
Documentation of SimpleNamespace mentions:
Shouldn't that cover the usecases brought up here? |
the same way we now have
TypedDict
, it would be nice to have typed SimpleNamespace with equivalent semantics, so that nested structures can be easily checked. egThe text was updated successfully, but these errors were encountered: