Skip to content

"RuntimeWarning: assigning None to unbound local": an inscrutable error #124118

@wyattscarpenter

Description

@wyattscarpenter

Documentation

RuntimeWarning: assigning None to unbound local ← I get this periodically since upgrading to python 3.12, for various lines of library code somewhere deep in my project's dependencies, and it seems like there's no documentation for it online? It's not even clear to me from the error message why this would be a bad thing to happen. These warnings generally seem to show up in list comprehensions. I don't know how to fix them or what they indicate. Maybe it's even a bug in python! I'm using Python 3.12.6 on Windows 10.

Here's an example from today:

C:\[...]\.venv\Lib\site-packages\asttokens\util.py:173: RuntimeWarning: assigning None to unbound local 'n'
  if isinstance(c, type) and issubclass(c, ast.expr)} |
C:\[...]\.venv\Lib\site-packages\asttokens\util.py:173: RuntimeWarning: assigning None to unbound local 'c'
  if isinstance(c, type) and issubclass(c, ast.expr)} |

Here's the line it's complaining about: https://github.com/gristlabs/asttokens/blob/2ff0e8d157fa89c22fe16839ab060b33f4c888bd/asttokens/util.py#L173

Here's another:

C:\[...]\.venv\Lib\site-packages\scipy\sparse\__init__.py:315: RuntimeWarning: assigning None to unbound local 's'
  __all__ = [s for s in dir() if not s.startswith('_')]

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions