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

Support Type[] type with delegate #275

Closed
sobolevn opened this issue Jul 13, 2021 · 6 comments · Fixed by #316
Closed

Support Type[] type with delegate #275

sobolevn opened this issue Jul 13, 2021 · 6 comments · Fixed by #316
Labels
enhancement New feature or request

Comments

@sobolevn
Copy link
Member

sobolevn commented Jul 13, 2021

Currently, we cannot express something like:

@some.instance(Type[MyClass], delegate=MyDelegate)
def _some_type_myclass(instance: Type[MyClass]) -> int: ...

We can only dispatch on type and that's it.
I think that this feature is useful.

Related #264
Related #274

@sobolevn sobolevn added the enhancement New feature or request label Jul 13, 2021
@thepabloaguilar
Copy link
Member

In fact we cannot express the example below without delegate too since Type is a generic thing:

@some.instance(Type[MyClass])
def _some_type_myclass(instance: Type[MyClass]) -> int: ...

What's the goal of this issue, enable Type in .instance or enable Type just for delegated typeclasses?

@sobolevn
Copy link
Member Author

sobolevn commented Oct 3, 2021

Yes, you are right! It should be:

@some.instance(delegate=MyTypeDelegate)
def _some_type_myclass(instance: Type[MyClass]) -> int: ...

@thepabloaguilar
Copy link
Member

So, what we need to do here? Like, the delegated classes are something that the users pass and that have the highest priority when we're evaluating the values

@sobolevn
Copy link
Member Author

sobolevn commented Oct 3, 2021

We need to make sure that the example above works and type-checks 🙂

@thepabloaguilar
Copy link
Member

thepabloaguilar commented Oct 3, 2021

I'd like to propose that we provide some delegate classes. Like this one that will check a Type because in order to do that check the users must know how to use get_origin and get_args from typing that's tricky sometimes!

P.S.: I made @example.instance(Type[MyClass]) works and all unit tests passed! Maybe we can add .type decorator

@sobolevn
Copy link
Member Author

sobolevn commented Oct 3, 2021

@thepabloaguilar great idea! Please, create a new issue for that! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants