Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute '__code__' #27

Open
choucavalier opened this issue Sep 4, 2023 · 1 comment
Open

Comments

@choucavalier
Copy link

When running the following self-contained example I'm hit with an AttributeError

Traceback (most recent call last):
  File "/home/user/env/lib/python3.11/site-packages/jurigged/codetools.py", line 493, in _process_child_correspondence
    orig.apply_correspondence(
  File "/home/user/env/lib/python3.11/site-packages/jurigged/codetools.py", line 704, in apply_correspondence
    new_obj = self.reevaluate(corr.new.node, glb)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/env/lib/python3.11/site-packages/jurigged/codetools.py", line 801, in reevaluate
    conform(self.get_object(), new_obj)
  File "/home/user/env/lib/python3.11/site-packages/codefind/registry.py", line 118, in conform
    self.conform(obj1, obj2.__code__)
  File "/home/user/env/lib/python3.11/site-packages/codefind/registry.py", line 123, in conform
    fv1 = obj1.__code__.co_freevars
          ^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__code__'

Any idea of what could be going wrong?

import asyncio
from pathlib import Path

import jurigged


async def slave():
    try:
        print('hello there')
        print("starting A")
        while True:
            print("A")
            await asyncio.sleep(1)
    except asyncio.CancelledError:
        print("stopped A")


async def master(tg: asyncio.TaskGroup):
    while True:
        task = asyncio.create_task(slave())
        await asyncio.sleep(4)
        task.cancel()


async def main():
    async with asyncio.TaskGroup() as tg:
        tg.create_task(master(tg))


if __name__ == "__main__":
    jurigged.watch(str(Path.cwd() / "asynctgtest.py"))
    asyncio.run(main())
@breuleux
Copy link
Owner

breuleux commented Sep 7, 2023

What seems to happen is that the codefind module collects function codes first when it is loaded (when import jurigged happens), and then when new files are imported. The functions in asynctgtest.py are therefore not picked up, because they are defined after the collection, but also after the file is imported.

I'll try to come up with a proper solution (and maybe a better error message), but in the meantime you can move import jurigged after the definition of main and it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants