-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Export DataclassInstance
protocol from _typeshed
#9676
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to just put it in _typeshed/__init__.pyi
? It feels a bit small to go in its own file. We can always move it to a dataclasses-specific file later if we add more dataclasses-specific protocols or aliases.
Also: I'd like to add a comment noting that the protocol is quasi-experimental, and linking to the pyright issue. The type won't work as intended for pyright users unless and until the pyright issue is reconsidered (or we think of another way of doing this in the stubs).
This comment has been minimized.
This comment has been minimized.
DataclassInstance
protocolDataclassInstance
protocol from _typeshed
Thanks! |
Diff from mypy_primer, showing the effect of this PR on open source code: porcupine (https://github.com/Akuli/porcupine)
- porcupine/utils.py:408: note: def asdict(obj: _DataclassInstance) -> Dict[str, Any]
+ porcupine/utils.py:408: note: def asdict(obj: DataclassInstance) -> Dict[str, Any]
- porcupine/utils.py:408: note: def [_T] asdict(obj: _DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T
+ porcupine/utils.py:408: note: def [_T] asdict(obj: DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:1862: error: Incompatible types in assignment (expression has type "Union[Type[_DataclassInstance], Type[Any], Callable[P, R], Callable[..., Any], DataClass_]", variable has type overloaded function) [assignment]
+ src/hydra_zen/structured_configs/_implementations.py:1862: error: Incompatible types in assignment (expression has type "Union[Type[DataclassInstance], Type[Any], Callable[P, R], Callable[..., Any], DataClass_]", variable has type overloaded function) [assignment]
core (https://github.com/home-assistant/core)
- homeassistant/components/p1_monitor/diagnostics.py:45: error: Argument 1 to "asdict" has incompatible type "Optional[Any]"; expected "_DataclassInstance" [arg-type]
+ homeassistant/components/p1_monitor/diagnostics.py:45: error: Argument 1 to "asdict" has incompatible type "Optional[Any]"; expected "DataclassInstance" [arg-type]
- homeassistant/components/zwave_js/discovery.py:78: note: def asdict(obj: _DataclassInstance) -> Dict[str, Any]
+ homeassistant/components/zwave_js/discovery.py:78: note: def asdict(obj: DataclassInstance) -> Dict[str, Any]
- homeassistant/components/zwave_js/discovery.py:78: note: def [_T] asdict(obj: _DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T
+ homeassistant/components/zwave_js/discovery.py:78: note: def [_T] asdict(obj: DataclassInstance, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T]) -> _T
|
Add
DataclassInstance
protocol to_typeshed
. Especially when dealing with mixin classes, it's quite common to have to use it. Moving it to_typeshed
means users can import it from there without having to reimplement it themselves.Followup to #9362 (comment)
/CC @AlexWaygood