rdancer / brute-lee

LeetCode: All problems; all languages; brute force.
MIT License
25 stars 1 forks source link

local variable 'last_buffer_line' referenced before assignment #12

Open rdancer opened 1 year ago

rdancer commented 1 year ago

Update the regexp in the last_return_line block preceding the error.


Failed to solve the problem.
Unknown error. Screenshot saved to screenshot.png
local variable 'last_buffer_line' referenced before assignment
Traceback (most recent call last):
  File "/Users/rdancer/code/leetcode/brute-lee/solver.py", line 439, in extract_return_value
    js_value = json.loads(return_value)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./main.py", line 164, in <module>
    raise e
  File "./main.py", line 124, in <module>
    solver.solve(page, problem_url, success_callback)
  File "/Users/rdancer/code/leetcode/brute-lee/solver.py", line 201, in solve
    self._submit()
  File "/Users/rdancer/code/leetcode/brute-lee/solver.py", line 276, in _submit
    self.convert_to_compressed()
  File "/Users/rdancer/code/leetcode/brute-lee/solver.py", line 476, in convert_to_compressed
    return_value = self.extract_return_value(js_code=js_code)
  File "/Users/rdancer/code/leetcode/brute-lee/solver.py", line 447, in extract_return_value
    match = re.search(r"buffer\s*=\s*(.*)", last_buffer_line)
UnboundLocalError: local variable 'last_buffer_line' referenced before assignment
rdancer commented 1 year ago

I think this happens when the solver is compressing a solution, and the return statement looks like

return someMangleFunction([...
 ][testNumber++])

whereas the code expects

return [...
 ][testNumber++]

Then it won't parse correctly, so a buffer = [... statement is sought but not found, so last_buffer_line, which would point to the last such statement remains undefiend.

If that's the case, this is a problem with singleLinkedListify() and binaryTreeify() and friends, and big solutions, and will be dealt with when rewriting the compression code.