locals() not working in tensorflow.function decorator 
Easily reproducible: see [gist](https://colab.research.google.com/gist/nrwahl2/b083eacf2542a2310740e8e14ed6ebb0/59725.ipynb).

When the decorator is used, the local scope appears to be overwritten within the for loop:
```
With decorator, before for loop
dict_keys(['inputs', 'application_order', 'method', 'fscope', 'ag__'])
In for loop
dict_keys(['itr', 'application', 'continue_', 'ag__', 'break_', 'fscope'])

Without decorator, before for loop
dict_keys(['inputs', 'application_order', 'method'])
In for loop
dict_keys(['inputs', 'application_order', 'method', 'application'])
```

The decorator transforms the function pretty substantially as shown in the gist, so that the loop body itself is a function and has its own scope. @nrwahl2 Yah! that is like c/c++ behaviour, where loops have there own scope (might be because it is compiling it like c/c++ to get ([tf.Graph](https://www.tensorflow.org/api_docs/python/tf/Graph))).  (Same in both stable and tf-nightly version). 
So, what can be done to get python like behaviour in decorator?  @MegaCreater Good question :) I'm new to TF and I'm still getting familiar with how the code base is structured. I don't have an idea for a fix yet.

Perhaps we could parse `locals()` calls so that they refer to the original local variables dict within the transformed for loop (this might be complicated or not feasible); or maybe we need to document it as a limitation of `@tf.function`. I'm interested to hear what the regular contributors think. @sachinprasadhs,
I was able to reproduce the issue on tensorflow v2.11 and nightly. Kindly find the gist of it [here](https://colab.research.google.com/gist/tilakrayal/a48c82ea8b273a479dfc21824ab0e2c7/59725.ipynb).  @tilakrayal or @sachinprasadhs plz have a look ... Hi, Since the `tf.function` runs in a graph mode, the variables which are not used or watched will not b traced in the graph and hence you are getting an error.
Please refer the [limitations](https://www.tensorflow.org/guide/function#limitations) and guidelines for the tf.function to understand in detail. Thanks So what can be done to get normal python like mode ?  Currently it falls under the limitations of `tf.function()`, you try try wrapping `tf.py_function ` https://www.tensorflow.org/api_docs/python/tf/py_function  inside tf.function. 
If it still fails, you need to execute it outside tf.function which uses eager mode instead of graph mode. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59725">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/59725">No</a>

Issue Type -> Bug
Have you reproduced the bug with TF nightly? -> No
Tensorflow Version -> v2.11.0-rc2-17-gd5b57ca93e5,  2.11.0
Custom Code -> Yes
OS Platform and Distribution -> Google colab 

#### Standalone code to reproduce the issue

```python3
import tensorflow as tf
@tf.function 
def sample_function(inputs:tf.Tensor,application_order:list=['method_3','method_1','method_2']):

  def method_1(inputs:tf.Tensor): return inputs*2                               # some complex code  
  def method_2(inputs:tf.Tensor): return inputs/2                               # some complex code
  def method_3(inputs:tf.Tensor): return inputs*3                               # some complex code

  print(locals().keys())                                                        # check all methods ! work fine all are here as dictionary

  for application in application_order:
    inputs=locals()[application](inputs)                                        # ERROR with tensorflow.function decorator 
  
  return inputs

sample_function(tf.random.normal((1,3,3,1)))                                    # call function # ERROR
```

#### Relevant log output
```shell
dict_keys(['application_order', 'do_return', 'retval_', 'method_1', 'method_2', 'method_3', 'fscope', 'ag__', 'inputs'])

..... 

KeyError: in user code:

    File "<ipython-input-128-82f7957c05a2>", line 12, in sample_function  *
        inputs=locals()[application](inputs)                                        # ERROR with tensorflow.function decorator

    KeyError: 'method_3'
```

#### Work fine without tensorflow.function
```python3
import tensorflow as tf
#@tf.function 
def sample_function(inputs:tf.Tensor,application_order:list=['method_3','method_1','method_2']):

  def method_1(inputs:tf.Tensor): return inputs*2                               # some complex code  
  def method_2(inputs:tf.Tensor): return inputs/2                               # some complex code
  def method_3(inputs:tf.Tensor): return inputs*3                               # some complex code

  print(locals().keys())                                                        # check all methods ! work fine all are here as dictionary

  for application in application_order:
    inputs=locals()[application](inputs)                                        # working fine as normal function !!!!!!!!! 
  
  return inputs

sample_function(tf.random.normal((1,3,3,1)))                                    # call function # works fine
```
#### Relevant log output
```shell
dict_keys(['inputs', 'application_order', 'method_1', 'method_2', 'method_3'])
<tf.Tensor: shape=(1, 3, 3, 1), dtype=float32, numpy=
....

```
