Skip to content

[reproducible+minimized] AttributeError: 'NoneType' object has no attribute '__code__' #51

@timotheecour

Description

@timotheecour

reproducible + minimized test case:

code1,code2,code3=gen_testcase_bug()

write code1 to /tmp/test.py and run python -u /tmp/test.py: works as intented (starts printing v1)
wait a second, write code 2: works as intended (starts printing v2)
wait a second, write code 3: it shows an error: AttributeError: 'NoneType' object has no attribute 'code', and also doesn't update the code (keeps printing v2 instead of v3)

def gen_testcase_bug():
  code1 = """
  def fn(i):
    def sub(j):
      return j
    print(i, "v1", sub(i))
    time.sleep(0.1)
"""
  code2 = """
  def sub3(j):
      return j
  def fn(i):
    def sub(j):
      return j
    print(i, "v2", sub(i))
    time.sleep(0.1)
"""

  code3 = """
  def sub3(j):
      return j
  def fn(i):
    def sub(j):
      return j
    print(i, "v3", sub(i))
"""

  ret = """
import time
import jurigged
import sys
file = sys.argv[0]
jurigged.watch([file], poll=1)
def main():
  {}
  for i in range(1000):
    try:
      fn(i)
    except Exception as e:
      import traceback
      traceback.print_exc()
      time.sleep(0.1)
main()
"""
  return ret.format(code1), ret.format(code2), ret.format(code3)
Traceback (most recent call last):
  File "/pathto/jurigged/codetools.py", line 533, in _process_child_correspondence
    orig.apply_correspondence(
  File "/pathto/jurigged/codetools.py", line 747, in apply_correspondence
    self.recode(new_code, recode_current=False)
  File "/pathto/jurigged/codetools.py", line 735, in recode
    conform(co, subcode, use_cache=use_cache)
  File "/pathto/codefind/registry.py", line 144, in conform
    fv1 = obj1.__code__.co_freevars
          ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__code__'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions