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

inheritance_diagram AttributeError: 'NoneType' object has no attribute 'groups' #4019

Closed
skidzo opened this issue Aug 23, 2017 · 8 comments
Closed
Labels
extensions:graphviz The `sphinx.ext.graphviz` or `sphinx.ext.inheritance_diagram` extensions type:bug
Milestone

Comments

@skidzo
Copy link

skidzo commented Aug 23, 2017

Subject: Exception occurs on make latexpdf in try_import of sphinx/ext/inheritance_diagram.py

Problem

Most Propably a user Error

Exception occurred:
  File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 83, in try_import
    modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
AttributeError: 'NoneType' object has no attribute 'groups'
The full traceback has been saved in /tmp/sphinx-err-0kr1ytc1.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Makefile:27: die Regel für Ziel „latexpdf“ scheiterte
make: *** [latexpdf] Fehler 1

Procedure to reproduce the problem

make latexpdf

Error logs / results

> # Sphinx version: 1.6.3
> # Python version: 3.6.0 (CPython)
> # Docutils version: 0.14 
> # Jinja2 version: 2.9.6
> # Last messages:
> #   updating environment:
> #   
> #   [extensions changed] 8 added, 0 changed, 0 removed
> #   
> #   reading sources... [ 12%] aus
> #   
> #   base-path: /home/user/some
> #   
> #   reading sources... [ 25%] fileformat
> #   
> # Loaded extensions:
> #   alabaster (0.7.10) from /home/johannes/anaconda3/lib/python3.6/site-packages/alabaster/__init__.py
> #   sphinx.ext.autodoc (1.6.3) from /home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/autodoc.py
> #   sphinx.ext.graphviz (1.6.3) from /home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/graphviz.py
> #   sphinx.ext.inheritance_diagram (1.6.3) from /home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py
> Traceback (most recent call last):
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 80, in try_import
>     __import__(objname)
> ModuleNotFoundError: No module named '.'
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/cmdline.py", line 306, in main
>     app.build(opts.force_all, filenames)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/application.py", line 339, in build
>     self.builder.build_update()
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 326, in build_update
>     self.build(['__all__'], to_build)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 344, in build
>     updated_docnames = set(self.env.update(self.config, self.srcdir, self.doctreedir))
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/environment/__init__.py", line 583, in update
>     self._read_serial(docnames, self.app)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/environment/__init__.py", line 602, in _read_serial
>     self.read_doc(docname, app)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/environment/__init__.py", line 723, in read_doc
>     pub.publish()
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/core.py", line 217, in publish
>     self.settings)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/io.py", line 74, in read
>     self.parse()
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/readers/__init__.py", line 78, in parse
>     self.parser.parse(self.input, document)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/__init__.py", line 191, in parse
>     self.statemachine.run(inputlines, document, inliner=self.inliner)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 171, in run
>     input_source=document['source'])
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 239, in run
>     context, state, transitions)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 460, in check_line
>     return method(match, context, next_state)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2753, in underline
>     self.section(title, source, style, lineno - 1, messages)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 327, in section
>     self.new_subsection(title, lineno, messages)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
>     node=section_node, match_titles=True)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
>     node=node, match_titles=match_titles)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 196, in run
>     results = StateMachineWS.run(self, input_lines, input_offset)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 239, in run
>     context, state, transitions)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 460, in check_line
>     return method(match, context, next_state)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2328, in explicit_markup
>     self.explicit_list(blank_finish)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2358, in explicit_list
>     match_titles=self.state_machine.match_titles)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 319, in nested_list_parse
>     node=node, match_titles=match_titles)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 196, in run
>     results = StateMachineWS.run(self, input_lines, input_offset)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 239, in run
>     context, state, transitions)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/statemachine.py", line 460, in check_line
>     return method(match, context, next_state)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2631, in explicit_markup
>     nodelist, blank_finish = self.explicit_construct(match)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2338, in explicit_construct
>     return method(self, expmatch)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2081, in directive
>     directive_class, match, type_name, option_presets)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/docutils/parsers/rst/states.py", line 2130, in run_directive
>     result = directive_instance.run()
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 342, in run
>     private_bases='private-bases' in self.options)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 144, in __init__
>     classes = self._import_classes(class_names, currmodule)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 156, in _import_classes
>     classes.extend(import_classes(name, currmodule))
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 100, in import_classes
>     target = try_import(currmodule + '.' + name)
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 83, in try_import
>     modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
> AttributeError: 'NoneType' object has no attribute 'groups'

Expected results

No Exception even if object is None

Reproducible project / your project

not necessary

Environment info

  • OS: <Unix/Linux/Mac/Win/other with version>
  • Python version: Python 3.6.0 |Anaconda custom (64-bit)
  • Sphinx version: Sphinx-1.6.3-py2.py3-none-any.whl
  • sphinx.ext.inheritance_diagram
@dpizetta
Copy link
Contributor

dpizetta commented Sep 4, 2017

Hi guys, I have the same problem here and I propose a solution here.

In the function try_import the parameter objname is unicode, so this solution I proposed is treating the consequence of passing a non-unicode parameter, in this case, None - NoneType.

This error breaks the making process, so I am using this fix until get into the real cause.

What do you think about this fix? Tks

@skidzo
Copy link
Author

skidzo commented Sep 5, 2017

the error happens, for example, when there are modules, that can not be found, which should not break the making process. I would agree to your solution, and additionally an ERROR Message, that at least shouts the name of the module that can not be found, would be nice to have.

@dpizetta
Copy link
Contributor

dpizetta commented Sep 5, 2017

Your suggestion, is a good one too, but particularly don't like to call two times the function, one for test and another for using it if passes. Both should be enough for now.

I looked into the code and found that the error could be generated by the [docutils parser (https://github.com/dpizetta/sphinx/blob/master/sphinx/ext/inheritance_diagram.py#L332). The parser includes strings ":parts:" and "1" as classes into the list of classes.

.. inheritance-diagram:: aa.bb.cc
   :parts: 1

This part is extracted from the module doc. Just one of my files get this problem, but in this file I have lots of imports (~20), so I couldn't find why this is generated.

More details: The function try_import() is called from import_classes() that receives the list of classes from InheritanceGraph class. This one is created in InheritanceDiagram, that is reimplemented from Directive of docutils which parses files.

Finally: I think that is not necessary throw an error message this moment if the problem that occurs in your code is the same, because saying just that some file has this problem (with "parts" and "1") may not help, returning None is enough to not break the making process. If anyone is getting the problem that it not finds some "real" module I agree to include the error message.

Could you test if this problem is the same (getting names)? Any other suggestions?

@dpizetta
Copy link
Contributor

dpizetta commented Sep 5, 2017

Sorry, in your text there is the name of the not found module, that already produces a error message:

> Traceback (most recent call last):
>   File "/home/johannes/anaconda3/lib/python3.6/site-packages/sphinx/ext/inheritance_diagram.py", line 80, in try_import
>     __import__(objname)
> ModuleNotFoundError: No module named '.'
> 
> During handling of the above exception, another exception occurred:`

, but it tries to handle that exception and then goes to another one:

>     modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
> AttributeError: 'NoneType' object has no attribute 'groups'

So, if it was the case, just return None is suficient for the problem.

@skidzo
Copy link
Author

skidzo commented Sep 7, 2017

yep, for me it really is, I'm happy :-)

@tk0miya tk0miya added this to the 1.6.7 milestone Jan 31, 2018
@tk0miya
Copy link
Member

tk0miya commented Jan 31, 2018

Is there anything I can do for this?
I also would like to fix this, but I don't know how to reproduce.

@dpizetta
Copy link
Contributor

Hi, I can submit my PR. The problem is that I don't figure out what is the real cause of the problem. So I can't create a test for it. I'm using this fix, and I didn't find any problem with it. For me, this is just a logic problem (return of match is None), and it still keeps warning about the not found module. May you can accept the PR. Any other ideas?

modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
AttributeError: 'NoneType' object has no attribute 'groups'

@tk0miya
Copy link
Member

tk0miya commented Jan 31, 2018

I noticed invalid modname causes an AttributeError.

.. inheritance-diagram:: :)
...
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 357, in run
    top_classes=node['top-classes'])
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 140, in __init__
    classes = self._import_classes(class_names, currmodule)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 152, in _import_classes
    classes.extend(import_classes(name, currmodule))
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 100, in import_classes
    target = try_import(name)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 79, in try_import
    modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
AttributeError: 'NoneType' object has no attribute 'groups'

Exception occurred:
  File "/Users/tkomiya/work/sphinx/sphinx/ext/inheritance_diagram.py", line 79, in try_import
    modname, attrname = module_sig_re.match(objname).groups()  # type: ignore
AttributeError: 'NoneType' object has no attribute 'groups'

@dpizetta could you make a PR please?

@tk0miya tk0miya modified the milestones: 1.6.7, 1.7 Feb 1, 2018
tk0miya added a commit that referenced this issue Feb 2, 2018
Fix #4019: exception treatment for AttributeError stopping make process
@tk0miya tk0miya closed this as completed Feb 2, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2021
@AA-Turner AA-Turner added extensions:graphviz The `sphinx.ext.graphviz` or `sphinx.ext.inheritance_diagram` extensions and removed extensions labels Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:graphviz The `sphinx.ext.graphviz` or `sphinx.ext.inheritance_diagram` extensions type:bug
Projects
None yet
Development

No branches or pull requests

4 participants