alexmojaki / alexmojaki/birdseye

ValueError if traced code contains match-case statements

Open
#108 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.7k
Forks
73
PR merge metrics
No merged PRs in 30d

Description

Hi, big fan.

As far as I dived into errors that I caught when tried to use birdseye, it has a hard time dealing with an AST of match...case expressions. I've got various errors depend on comparison type in the expression.

python 3.11.10
birdseye 0.10.0, also 0.9.5

Example with values comparison:
```python
import birdseye.trace_module_deep

def func():
banana = "BANANA"
match banana:
case 1:
None
case "BANANA":
print("YAY")
case _:
print("OOPS")

func()
```
What happened:
```
$ python reproduce.py

Traceback (most recent call last):
File ".../reproduce.py", line 1, in
import birdseye.trace_module_deep
File ".../venv/lib/python3.11/site-packages/birdseye/trace_module_deep.py", line 3, in
eye.trace_this_module(1, deep=True)
File ".../venv/lib/python3.11/site-packages/birdseye/bird.py", line 473, in trace_this_module
self.exec_string(source, filename, frame.f_globals, frame.f_locals, deep)
File ".../venv/lib/python3.11/site-packages/birdseye/bird.py", line 480, in exec_string
traced_file = self.compile(source, filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../venv/lib/python3.11/site-packages/birdseye/bird.py", line 147, in compile
traced_file = super(BirdsEye, self).compile(source, filename, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../venv/lib/python3.11/site-packages/birdseye/tracer.py", line 168, in compile
return TracedFile(self, source, filename, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../venv/lib/python3.11/site-packages/birdseye/tracer.py", line 76, in __init__
self.code = compile(new_root, filename, "exec", dont_inherit=True, flags=flags) # type: CodeType
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: patterns may only match literals and attribute lookups
```

Example with the type matching:
```python
import birdseye.trace_module_deep

def func():
banana = "BANANA"
match banana:
case int():
None
case str():
print("YAY")
case _:
print("OOPS")

func()
```

What happened:
```
$ python reproduce.py
Traceback (most recent call last):
File "/home/rzayrullin/fellow-craft/reproduce.py", line 1, in
import birdseye.trace_module_deep
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/trace_module_deep.py", line 3, in
eye.trace_this_module(1, deep=True)
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/bird.py", line 473, in trace_this_module
self.exec_string(source, filename, frame.f_globals, frame.f_locals, deep)
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/bird.py", line 480, in exec_string
traced_file = self.compile(source, filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/bird.py", line 147, in compile
traced_file = super(BirdsEye, self).compile(source, filename, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/tracer.py", line 168, in compile
return TracedFile(self, source, filename, flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/rzayrullin/fellow-craft/venv/lib/python3.11/site-packages/birdseye/tracer.py", line 76, in __init__
self.code = compile(new_root, filename, "exec", dont_inherit=True, flags=flags) # type: CodeType
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: MatchClass cls field can only contain Name or Attribute nodes.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.