# Why not real anonymous functions?

**URL:** <https://discuss.python.org/t/why-not-real-anonymous-functions/44513>\
**Category:** Ideas\
**Created:** [January 30, 2024, 2:27am UTC](https://discuss.python.org/t/why-not-real-anonymous-functions/44513 "2024-01-30T02:27:09Z")\
**Posts on this page:** 1\
**Showing post:** 64

<div class="post-metadata">

**Author:** ![kfdf](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kfdf/32/14474_2.png) [@kfdf](https://discuss.python.org/u/kfdf)\
**Post date:** [February 1, 2024, 9:35am UTC](https://discuss.python.org/t/why-not-real-anonymous-functions/44513/64 "2024-02-01T09:35:35Z")

</div>

My 2 cents. Maybe “tail defs” can be a good enough solution to cover common use cases?

So that this:

```python
def deco(f):
  @wraps(f) 
  def wrapper(*args, **kwargs):
    print('calling f')
    return f(*args, **kwargs)
  return wrapper

def callback(framework_arg):
  pass

api_call(1, 2, callback, kw="example")

```

can become this:

```python
def deco(f):
  return @wraps(f) def (*args, **kwargs):
    print('calling f')
    return f(*args, **kwargs)

api_call(1, 2, lambda, kw="example") def ():
  pass

```

So, basically, a single trailing anonymous def after a statement defines a function that can be referenced elsewhere in the statement.

Frankly, I don’t like how it looks, it’s quite limited and it barely saves space and keystrokes, but it helps to put things in more natural order, and conceptualy not far off from how decorators work today.

---

_[View the full topic](https://discuss.python.org/t/why-not-real-anonymous-functions/44513)._
