[issue38940] Add a new functools.cast() function

2019-11-29 Thread Brett Cannon
Brett Cannon added the comment: First off, thanks for the suggestion! But there are two things to say about this. One, that isn't actually casting as Python doesn't have the concept of casting like in statically typed languages since everything is dynamically typed. Two, the solution is so

[issue38940] Add a new functools.cast() function

2019-11-29 Thread Pablo Galindo Salgado
Change by Pablo Galindo Salgado : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue38940] Add a new functools.cast() function

2019-11-29 Thread Ugra Dániel
Ugra Dániel added the comment: Currently, the closest functionality I can think of (using standard library functions only): @functools.partial(lambda func: functools.wraps(func)(lambda *args, **keywords: list(func(*args, **keywords Or without proper wrapping: @functools.partial(lambda

[issue38940] Add a new functools.cast() function

2019-11-29 Thread Ugra Dániel
New submission from Ugra Dániel : In some cases it would be really helpful to have a decorator which automagically casts returned value to a different type. Particularly, instead of writing something like this: def example(): result = [] for ...: result.append(item)