Skip to content
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

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

Open
lazytype opened this issue Nov 6, 2019 · 1 comment

Comments

@lazytype
Copy link
Contributor

lazytype commented Nov 6, 2019

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

@ilevkivskyi
Copy link
Member

On one hand this would be pretty straightforward to add, but on another hand we should be careful with managing extra dependencies caused by this (especially in fine-grained mode, that may be tricky).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants