(fixed) Nbdev_preview - AttributeError

Hi

I am following 90’ video from Jeremy and Hamel. (nbdev tutorial – zero to published project in 90 minutes
)
Using my own tobe library which is called dataset_tools
I am at the step to generate documentation, running nbdev_preview.
It worked beautifully. Just played a little bit with some minnor modifications, were pleased to see the direct impact on doc.

But then an error happened doc suddenly were not updated anymore. With errors in console.
And now if I re-run nbdev_preview I have this error

(dataset_tools) guillaume@LL11LPC0PQARQ:~/git/dataset_tools$ nbdev_preview
Traceback (most recent call last):
  File "/home/guillaume/miniconda/envs/dataset_tools/bin/nbdev_preview", line 8, in <module>
    sys.exit(preview())
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/quarto.py", line 278, in preview
    nbdev_quarto.__wrapped__(path, preview=True, **kwargs)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/quarto.py", line 256, in nbdev_quarto
    nbdev.doclinks._build_modidx(skip_exists=True)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 86, in _build_modidx
    res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 65, in _get_modidx
    if isinstance(tree, _def_types): _stor(patch_name(tree), tree)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 43, in patch_name
    return _sym_nm(a,o)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 25, in _sym_nm
    def _sym_nm(klas, sym): return f'{unparse(klas).strip()}.{sym.name}'
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/__init__.py", line 13, in unparse
    Unparser(tree, file=v)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/unparser.py", line 38, in __init__
    self.dispatch(tree)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/unparser.py", line 65, in dispatch
    meth = getattr(self, "_"+tree.__class__.__name__)
AttributeError: 'Unparser' object has no attribute '_NoneType'

Here is the error I got in the console at the time I made the modification in my code.

GET: /container.html
Traceback (most recent call last):
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/IPython/core/formatters.py", line 222, in catch_format_error
    r = method(self, *args, **kwargs)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/IPython/core/formatters.py", line 343, in __call__
    return method()
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/showdoc.py", line 170, in _repr_markdown_
    src = NbdevLookup().code(self.fn)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 183, in __init__
    self.entries = {o.name: _qual_syms(o.load()) for o in list(pkg_resources.iter_entry_points(group='nbdev'))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 183, in <dictcomp>
    self.entries = {o.name: _qual_syms(o.load()) for o in list(pkg_resources.iter_entry_points(group='nbdev'))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2471, in load
    return self.resolve()
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2477, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'dataset_tools._modidx'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/guillaume/miniconda/envs/dataset_tools/bin/nbdev_filter", line 8, in <module>
    sys.exit(nbdev_filter())
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/cli.py", line 64, in nbdev_filter
    with redirect_stdout(dn): filt.nb_proc(nb).process()
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/process.py", line 122, in process
    for proc in self.procs: self._proc(proc)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/process.py", line 115, in _proc
    for cell in self.nb.cells: self._process_cell(proc, cell)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/process.py", line 106, in _process_cell
    if callable(proc) and not _is_direc(proc): cell = opt_set(cell, proc(cell))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/processors.py", line 290, in __call__
    if self.k.exc: raise Exception(f"Error{' in notebook: '+title if title else ''} in cell {cell.idx_} :\n{cell.source}") from self.k.exc[1]
Exception: Error in notebook: container -- un container de datasets Pandas in cell 11 :
#|output: asis
#| echo: false
show_doc(Container)

I have given a look in github issues (closed and open) from fastai/nbdev repo but have not found something similar. Don’t know if someone has the same issue?
Will retry from a previous state to see.

I think this is more nbdev_export which is firing the error.
Guess that nbdev_export is called by nbdev_preview

(dataset_tools) guillaume@LL11LPC0PQARQ:~/git/dataset_tools$ nbdev_export
Traceback (most recent call last):
  File "/home/guillaume/miniconda/envs/dataset_tools/bin/nbdev_export", line 8, in <module>
    sys.exit(nbdev_export())
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/fastcore/script.py", line 119, in _f
    return tfunc(**merge(args, args_from_prog(func, xtra)))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 124, in nbdev_export
    _build_modidx()
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 86, in _build_modidx
    res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 65, in _get_modidx
    if isinstance(tree, _def_types): _stor(patch_name(tree), tree)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 43, in patch_name
    return _sym_nm(a,o)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/nbdev/doclinks.py", line 25, in _sym_nm
    def _sym_nm(klas, sym): return f'{unparse(klas).strip()}.{sym.name}'
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/__init__.py", line 13, in unparse
    Unparser(tree, file=v)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/unparser.py", line 38, in __init__
    self.dispatch(tree)
  File "/home/guillaume/miniconda/envs/dataset_tools/lib/python3.9/site-packages/astunparse/unparser.py", line 65, in dispatch
    meth = getattr(self, "_"+tree.__class__.__name__)
AttributeError: 'Unparser' object has no attribute '_NoneType'

I don’t know yet why but it seems linked to
#| export before @class

In the first version of my notebook, I have got as Jeremy showed:

@patch
def __eq__(self, cont_b:Container): return (self.cle, self.dataset.shape) == (cont_b.cle, cont_b.dataset.shape)

and then nbdev_preview just works. I then updated it to

#| export

@patch
def __eq__(self, cont_b:Container): return (self.cle, self.dataset.shape) == (cont_b.cle, cont_b.dataset.shape)

saved the notebook, the doc is instantly updated.
but when I quit nbdev_preview and re-run it. (or nbdev_export), I have this error.
If I remove #| export then it works back…

I am confused about how to fix that.

I have found the typo.

Should define what has to be patched.

#| export
@patch
def __eq__(self:Container, cont_b:Container): return (self.cle, self.dataset.shape) == (cont_b.cle, cont_b.dataset.shape)

See :Containerafter self

2 Likes