Skip to content

Feature request: Provide a type constructor that derives a Protocol from another type #7894

Open
@lazytype

Description

@lazytype

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))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions