diff --git a/pyupgrade.py b/pyupgrade.py
index 8e3bda3..a49ef68 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -1448,7 +1448,7 @@ class FindPy3Plus(ast.NodeVisitor):
         if self._scope_stack:
             if isinstance(node.ctx, ast.Load):
                 self._scope_stack[-1].reads.add(node.id)
-            elif isinstance(node.ctx, ast.Store):
+            elif isinstance(node.ctx, (ast.Store, ast.Del)):
                 self._scope_stack[-1].writes.add(node.id)
             else:
                 raise AssertionError(node)

py3-plus: AssertionError: del statement in function
pyupgrade 2.4.2

Minimal test case:

```py
def foo(bar):
    del bar
```

```
pyupgrade --py3-plus test.py
```

```
Traceback (most recent call last):
  File "./venv/bin/pyupgrade", line 8, in <module>
    sys.exit(main())
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 2680, in main
    ret |= _fix_file(filename, args)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 2638, in _fix_file
    contents_text = _fix_py3_plus(contents_text, args.min_version)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 2002, in _fix_py3_plus
    visitor.visit(ast_obj)
  File "/usr/lib64/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1705, in generic_visit
    super().generic_visit(node)
  File "/usr/lib64/python3.8/ast.py", line 368, in generic_visit
    self.visit(item)
  File "/usr/lib64/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1418, in _visit_sync_func
    self._visit_func(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1414, in _visit_func
    self.generic_visit(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1705, in generic_visit
    super().generic_visit(node)
  File "/usr/lib64/python3.8/ast.py", line 368, in generic_visit
    self.visit(item)
  File "/usr/lib64/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1705, in generic_visit
    super().generic_visit(node)
  File "/usr/lib64/python3.8/ast.py", line 368, in generic_visit
    self.visit(item)
  File "/usr/lib64/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/home/jon/venv/lib64/python3.8/site-packages/pyupgrade.py", line 1454, in visit_Name
    raise AssertionError(node)
AssertionError: <_ast.Name object at 0x7f6b26fd0a90>
```

Encountered in real life code: https://github.com/andymccurdy/redis-py/blob/7c0a67a5cb4a20aea44c590837b0e79c9c09c510/tests/test_multiprocessing.py#L157-L159
diff --git a/tests/yield_from_test.py b/tests/yield_from_test.py
index bda592a..5aa9c45 100644
--- a/tests/yield_from_test.py
+++ b/tests/yield_from_test.py
@@ -205,6 +205,11 @@ def test_fix_yield_from(s, expected):
             '    g()()\n',
             id='variable referenced after loop, but via nested function',
         ),
+        pytest.param(
+            'def f(x):\n'
+            '    del x\n',
+            id='regression with del ctx (#306)',
+        ),
     ),
 )
 def test_fix_yield_from_noop(s):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
3.9
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
cfgv==3.4.0
covdefaults==2.3.0
coverage==7.8.0
distlib==0.3.9
exceptiongroup==1.2.2
filelock==3.18.0
identify==2.6.9
iniconfig==2.1.0
nodeenv==1.9.1
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
pre_commit==4.2.0
pytest==8.3.5
-e git+https://github.com/asottile/pyupgrade.git@6eed58483836b7c951f9d1173c1c39700b87c722#egg=pyupgrade
PyYAML==6.0.2
tokenize_rt==6.1.0
tomli==2.2.1
virtualenv==20.29.3

name: pyupgrade
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - cfgv==3.4.0
      - covdefaults==2.3.0
      - coverage==7.8.0
      - distlib==0.3.9
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - identify==2.6.9
      - iniconfig==2.1.0
      - nodeenv==1.9.1
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pre-commit==4.2.0
      - pytest==8.3.5
      - pyyaml==6.0.2
      - tokenize-rt==6.1.0
      - tomli==2.2.1
      - virtualenv==20.29.3
prefix: /opt/conda/envs/pyupgrade

tests/yield_from_test.py::test_fix_yield_from_noop[regression
tests/yield_from_test.py::test_fix_yield_from[def tests/yield_from_test.py::test_fix_yield_from[async tests/yield_from_test.py::test_fix_yield_from[leave tests/yield_from_test.py::test_fix_yield_from_noop[def tests/yield_from_test.py::test_fix_yield_from_noop[variable tests/yield_from_test.py::test_targets_same tests/yield_from_test.py::test_fields_same
pyupgrade.py
pyupgrade.py