Feature request: Provide a type constructor that derives a Protocol from another type
Open
Nobody has claimed this yet.
feature
priority-1-normal
topic-protocols
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Please provide more information to help us understand the issue:
class Foo:
num: int = 1
msg: str = "hello"
FooProtocol = protocol(Foo, include_private=False)
FooLookalike = NamedTuple("FooLookalike", [("num", int), ("msg", str)])
# ok
maybe_foo: FooProtocol = FooLookalike(num=2, msg="bye")
# ok
maybe_foo = Foo()
# safely cast when using Fakes in a test
test_foo(cast(Foo, maybe_foo))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a Python example for deriving a Protocol from Foo and checking FooLookalike and Foo instances against it. No files, tests, or entry points are named, so first locate the existing Protocol and type-constructor handling; done means the shown assignments type-check and the cast example remains safe.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100