gristlabs / asttokens

Annotate Python AST trees with source text and token information
Apache License 2.0
172 stars 34 forks source link

RuntimeWarning: assigning None to unbound local #148

Closed wyattscarpenter closed 2 months ago

wyattscarpenter commented 2 months ago

Hello,

Today I was running my program and I was greeted with the following runtime warnings:

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)} |

The program seems to work fine

I am using Python 3.12.5 (I think these warnings are new in 3.12) and asttokens 2.4.1.

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

I submit this to you in case it helps you, or you know what it means, but I'm not holding my breath.

alexmojaki commented 2 months ago

If you can create a reproducible example, that'd be great. This might indicate a bug in CPython.

wyattscarpenter commented 2 months ago

That creating a repro will probably be very difficult, alas, because I don't really know the circumstances under which it's occurring the first time. (Your code is called by one of my dependencies, I think.) But I'll let you know if I figure one out!

wyattscarpenter commented 2 months ago

I opened a documentation issue about this to CPython, one thing led to another, and the fine folks there helped me figure out that it's my profiler causing the trouble, not your code. Sorry to bother you!