Repository: tensorflow
Issue: AutoGraph error when function is inside a match 
Labels: stat:awaiting tensorflower,type:bug,comp:autograph,TF 2.12

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

Yes

### Source

binary

### Tensorflow Version

2.13.0-dev20230501

### Custom Code

No

### OS Platform and Distribution

Google Colab

### Mobile device

_No response_

### Python version

3.10.11

### Bazel version

_No response_

### GCC/Compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

When a `tf.data.Dataset.map` function is defined inside a `match` scope and used by `tf.data.Dataset.apply` the AutoGraph fails. This should not happen, as the match statement should be irrelevant to the function definition. I suspect this error happens in more AutoGraph cases than just `tf.data.Dataset.map` via `tf.data.Dataset.apply`.

The issue is reproduced on Google Colab with both nightly (2.13.0-dev20230501) and 2.12.

### Standalone code to reproduce the issue

See https://colab.research.google.com/drive/1x07aUgISrYQohsG7FYmc70LeYjVcGixG#scrollTo=auSxkDSinh3R

```python
import tensorflow as tf
parameter = 'a'

match parameter:
    case 'a':
        def fn(ds):
            return ds.map(lambda x: x + 1)

dataset = tf.data.Dataset.range(1) \
    .apply(fn)

for x in dataset:
    print(x)
```


### Relevant log output

```shell
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 427, in converted_call
    converted_f = _convert_actual(target_entity, program_ctx)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/impl/api.py", line 269, in _convert_actual
    transformed, module, source_map = _TRANSPILER.transform(entity, program_ctx)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/transpiler.py", line 282, in transform
    return self.transform_function(obj, user_context)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/transpiler.py", line 466, in transform_function
    nodes, ctx = super(PyToPy, self).transform_function(fn, user_context)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/transpiler.py", line 342, in transform_function
    node, source = parser.parse_entity(fn, future_features=future_features)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/parser.py", line 145, in parse_entity
    return _parse_lambda(entity)
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/parser.py", line 275, in _parse_lambda
    lambda_nodes.extend(
  File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/autograph/pyct/parser.py", line 275, in <genexpr>
    lambda_nodes.extend(
  File "/usr/lib/python3.10/ast.py", line 390, in walk
    todo.extend(iter_child_nodes(node))
  File "/usr/lib/python3.10/ast.py", line 272, in iter_child_nodes
    for name, field in iter_fields(node):
  File "/usr/lib/python3.10/ast.py", line 260, in iter_fields
    for field in node._fields:
AttributeError: 'NoneType' object has no attribute '_fields'
WARNING:tensorflow:AutoGraph could not transform <function fn.<locals>.<lambda> at 0x7f9fc56e9870> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: 'NoneType' object has no attribute '_fields'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
2.13.0-dev20230501
Converted call: <function fn.<locals>.<lambda> at 0x7f9fc56e9870>
    args: (<tf.Tensor 'args_0:0' shape=() dtype=int64>,)
    kwargs: {}

Not allowed: <method-wrapper '__call__' of function object at 0x7f9fc56e9870>: default rule
Not allowed: <function fn.<locals>.<lambda> at 0x7f9fc56e9870>: default rule
<function fn.<locals>.<lambda> at 0x7f9fc56e9870> is not cached for subkey ConversionOptions[{}]
Error transforming entity <function fn.<locals>.<lambda> at 0x7f9fc56e9870>
WARNING: AutoGraph could not transform <function fn.<locals>.<lambda> at 0x7f9fc56e9870> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output.
Cause: 'NoneType' object has no attribute '_fields'
To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert
tf.Tensor(1, shape=(), dtype=int64)
```
</details>