You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No error in function definition that returns unbound T #13061
We'd only reject a plain type variable as a return type, but not things like list[T] where the type variable is a component of some other type. Returning list[T], for example, could be reasonable.
If a return type is an instance of TypeVarType but the return type is not present as a component in function argument types, generate an error.
You can use a TypeTraverserVisitor to traverse the argument types, and override visit_type_var to collect all the references to type variables within a type. See CollectAllInstancesQuery for an example of doing a similar thing.
@odesenfans The only example that I can think of is creating an empty container. For example, something like this:
defmake_bucket() ->Bucket[T]: ...
b: Bucket[int] =make_bucket() # similar to x: list[int] = list()b.add(1)
Usually you would just call the type object, but having a factory function seems like a plausible use case (e.g. we could do some extra things like logging or collect statistics in the factory function).
Activity
JukkaL commentedon Jul 16, 2022
Hints:
list[T]where the type variable is a component of some other type. Returninglist[T], for example, could be reasonable.TypeVarTypebut the return type is not present as a component in function argument types, generate an error.TypeTraverserVisitorto traverse the argument types, and overridevisit_type_varto collect all the references to type variables within a type. SeeCollectAllInstancesQueryfor an example of doing a similar thing.odesenfans commentedon Jul 16, 2022
Could you elaborate on why and when types like
list[T]could be acceptable ifTis not bound to any type?JukkaL commentedon Jul 16, 2022
@odesenfans The only example that I can think of is creating an empty container. For example, something like this:
Usually you would just call the type object, but having a factory function seems like a plausible use case (e.g. we could do some extra things like logging or collect statistics in the factory function).
Add unbound typevar check (#13166)
ilevkivskyi commentedon Sep 25, 2022
I think this was already fixed by #13166, but accidentally was not closed.