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

ability to explicitly specify generics in function calls / reified generics for functions #121

Closed
DetachHead opened this issue Dec 24, 2021 · 3 comments
Labels

Comments

@DetachHead
Copy link
Collaborator

DetachHead commented Dec 24, 2021

i swear i raised this before but cant find it

def foo(value: T): ...

foo[int](1)
@KotlinIsland
Copy link
Owner

KotlinIsland commented Dec 24, 2021

Could be tricky, here are a couple options

@Generic[T]
def foo(t: T): ...

def bar(t: T):...

bar(1) # type: bar[object](...)

generic_function(bar)[object](1)

Some of these could be used to reify the generic.

Or just

foo(1 as object)

@DetachHead DetachHead changed the title ability to explicitly specify generics in function calls ability to explicitly specify generics in function calls / reified generics for functions Jan 3, 2022
@KotlinIsland
Copy link
Owner

KotlinIsland commented Jan 19, 2022

This might look confusing, but I can't think of another way to get the type vars into the function

@Generic[T]
def foo(T, a: T):  # no need to annotate as mypy can infer it
    print(T)  # <class 'int'>
    print(a)  # False

foo[int](False)

Some questions that remain:

  • Would it be safe to infer at runtime?
    foo(1) # infer and pass int?
  • Why not just pass the type[T] without this wrapper?
    def foo(T, t: T): ...  # still infer it 😁
    foo(int, 1)

@KotlinIsland
Copy link
Owner

Duplicate-of KotlinIsland/basedtyping#86

@KotlinIsland KotlinIsland closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants