intersection_examples
intersection_examples copied to clipboard
Python Typing Intersection examples
I've been looking for a way to type Mock objects, and my understanding is that this would be a good fit: ```python mock_client: Intersection[Mock, ApiClient] = Mock(spec=ApiClient) ``` Or even...
TBD, see #16 **Edit: This issue is currently incomplete and is being used to transparently post components of it for review. Please hold comments on the following topics for now:**...
PR relating to https://github.com/CarliJoy/intersection_examples/issues/48. Still some work to be done on this, but feel free anyone to have a review if you'd like @CarliJoy @erictraut @NeilGirdhar @gvanrossum @DiscordLiz @vergenzt ....
## Summary I'm starting this thread as a fresh start on the Intersection PEP. We've come across various difficulties in formulating the Intersection PEP, and it's been a long road...
While reading through #29, I saw [this comment](https://github.com/CarliJoy/intersection_examples/issues/29#issuecomment-1854532691): > I think the most important thing that we're missing are motivating examples. So I figured I'd chime in with one that...
```python from collections.abc import Iterable from typing import Protocol, Self from django.db import models from django.db.models.query import QuerySet class SupportsActiveProtocol(Protocol): def make_active(self) -> None: ... def make_inactive(self) -> None: ......
The motivation is really uncompelling. It describes what intersections do, but not why we need them. I think it would be better to dig through the mypy issues to find...
I want to contribute a real life use case that we encountered which may justify the needs of Intersection types. Can anyone suggest an alternative without using Intersection? ```Py from...
Annotating 'Type object with particular constructor signature' requires intersection. Suppose we have a ```Py # returns cached instance of SomeClass or creates a new instance def get_cached_or_create(klass): if _is_cached(klass): return...
This is a typical use of the [PEP 681](https://peps.python.org/pep-0681/) `dataclass_transform`: ```python class DataclassInstance(Protocol): # See usefule_types.experimental.DataclassLike __dataclass_fields__: ClassVar[dict[str, dataclasses.Field[Any]]] @overload @dataclass_transform(frozen_default=True, field_specifiers=(field,)) def dataclass(*, init: bool = True, repr_: bool...