Nbdev_export: AttributeError: 'AugAssign' object has no attribute 'targets'

nbdev_prepare and nbdev_export are throwing an error at line 90 of nbdev/maker.py : AttributeError: 'AugAssign' object has no attribute 'targets' .

Any idea what this issue is about? (Updating nbdev & quarto didn’t help. )

Running on Ubuntu Linux. Traceback:

$ nbdev_export
Traceback (most recent call last):
  File "/fsx/shawley/envs/shazbot/bin/nbdev_prepare", line 8, in <module>
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/quarto.py", line 237, in prepare
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/doclinks.py", line 137, in nbdev_export
    for f in files: nb_export(f)
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/export.py", line 59, in nb_export
    mm.make(cells, all_cells, lib_path=lib_path)
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/maker.py", line 201, in make
    _all = self.make_all(all_cells)
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/maker.py", line 100, in make_all
    all_assigns = assigns.filter(lambda o: getattr(_targets(o)[0],'id',None)=='_all_')
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/fastcore/foundation.py", line 160, in filter
    return self._new(filter_ex(self, f=f, negate=negate, gen=gen, **kwargs))
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/fastcore/basics.py", line 642, in filter_ex
    return list(res)
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/maker.py", line 100, in <lambda>
    all_assigns = assigns.filter(lambda o: getattr(_targets(o)[0],'id',None)=='_all_')
  File "/fsx/shawley/envs/shazbot/lib/python3.8/site-packages/nbdev/maker.py", line 90, in _targets
    def _targets(o): return [o.target] if isinstance(o, ast.AnnAssign) else o.targets
AttributeError: 'AugAssign' object has no attribute 'targets'

What ‘targets’ is it looking for?

The offending notebook (audio-algebra/aa-mixer-toy.ipynb at main · drscotthawley/audio-algebra · GitHub) is similar to the other ones in the repo, and executes fine on several platforms.


I had some code in the exported cells that would have executed when the .py file was imported.

Moved those bit of code to other non-exported cells. Now all’s well.

1 Like

Looks like a bug - I’m guessing that last line in the stack trace needs to change to:

def _targets(o): return [o.target] if isinstance(o, (ast.AnnAssign,ast.AugAssign)) else o.targets

Can you please tell me which of your commits contains the code that failed, so I can try it out? Commits · drscotthawley/audio-algebra · GitHub

1 Like

Sure. This one had the failure:

1 Like

I got the same error. There seems to be something still wrong but here’s a (hopefully useful) clue:

This does not work:
befunde_df.BefundBefundIDCustomerMaterial7Count += '_' + g.cumcount().astype(str)

But this works:
befunde_df.BefundBefundIDCustomerMaterial7Count = befunde_df.BefundBefundIDCustomerMaterial7Count + '_' + g.cumcount().astype(str)

Although they mean the same thing. Could it be that there is a problem with the += operator while exporting?

I’ve made the change on github - give it a try and tell me if it resolves your problem please.