TypeError: unsupported operand type(s) for -: 'str' and 'int'

115 views
Skip to first unread message

Fernando Gómez

unread,
Sep 7, 2010, 4:36:08 PM9/7/10
to sphin...@googlegroups.com
Hi,

Can you give some advice regarding this exception? This is what the
console shows:

---------------------
Running Sphinx v1.0.3
loading pickled environment... not yet created
building [html]: targets for 56 source files that are out of date
updating environment: 56 added, 0 changed, 0 removed
reading sources... [ 98%] ui
Exception occurred:
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 371, in get_source_and_line
offset = lineno - self.input_offset - 1
TypeError: unsupported operand type(s) for -: 'str' and 'int'
The full traceback has been saved in /tmp/sphinx-err-DprByU.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.
---------------------

BTW, I'm using a custom extension.

The full traceback is here:

# Sphinx version: 1.0.3
# Docutils version: 0.7 release
# Jinja2 version: 2.5.2
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/cmdline.py",
line 173, in main
app.build(force_all, filenames)
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/application.py",
line 207, in build
self.builder.build_update()
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/builders/__init__.py",
line 198, in build_update
'out of date' % len(to_build))
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/builders/__init__.py",
line 218, in build
purple, length):
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/builders/__init__.py",
line 120, in status_iterator
for item in iterable:
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/environment.py",
line 515, in update_generator
self.read_doc(docname, app=app)
File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.0.3-py2.6.egg/sphinx/environment.py",
line 655, in read_doc
pub.publish()
File "/usr/local/lib/python2.6/dist-packages/docutils/core.py", line
203, in publish
self.settings)
File "/usr/local/lib/python2.6/dist-packages/docutils/readers/__init__.py",
line 69, in read
self.parse()
File "/usr/local/lib/python2.6/dist-packages/docutils/readers/__init__.py",
line 75, in parse
self.parser.parse(self.input, document)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/__init__.py",
line 157, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 170, in run
input_source=document['source'])
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 233, in run
context, state, transitions)
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 454, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 329, in section
self.new_subsection(title, lineno, messages)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 398, in new_subsection
node=section_node, match_titles=1)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 284, in nested_parse
node=node, match_titles=match_titles)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 233, in run
context, state, transitions)
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 454, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 329, in section
self.new_subsection(title, lineno, messages)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 398, in new_subsection
node=section_node, match_titles=1)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 284, in nested_parse
node=node, match_titles=match_titles)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 233, in run
context, state, transitions)
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 454, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2281, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2293, in explicit_construct
return method(self, expmatch)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2035, in directive
directive_class, match, type_name, option_presets)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 2086, in run_directive
result = directive_instance.run()
File "/home/fernando/unison/noweb/sphinx/docs/_extensions/noweb.py",
line 131, in run
text_nodes, messages = self.state.inline_text(code, '')
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 430, in inline_text
return self.inliner.parse(text, lineno, self.memo, self.parent)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 516, in parse
lineno)
File "/usr/local/lib/python2.6/dist-packages/docutils/parsers/rst/states.py",
line 779, in interpreted_or_phrase_ref
'without end-string.', line=lineno)
File "/usr/local/lib/python2.6/dist-packages/docutils/utils.py",
line 230, in warning
return self.system_message(self.WARNING_LEVEL, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/docutils/utils.py",
line 178, in system_message
source, line = self.locator(attributes.get('line'))
File "/usr/local/lib/python2.6/dist-packages/docutils/statemachine.py",
line 371, in get_source_and_line
offset = lineno - self.input_offset - 1
TypeError: unsupported operand type(s) for -: 'str' and 'int'


--
Fernando Gómez
Biblioteca "Antonio Monteiro"
INMABB (Conicet / Universidad Nacional del Sur)
Av. Alem 1253
B8000CPB Bahía Blanca, Argentina
Tel. +54 (291) 459 5116
http://inmabb.criba.edu.ar/

Fernando Gómez

unread,
Sep 7, 2010, 5:12:29 PM9/7/10
to sphin...@googlegroups.com
The error messages were obscure to me, but anyway I've found the
offending reST (simplified):

:ref:`foo <bar>`<baz>

Adding whitespace after the closing backquotes solves the issue:

:ref:`foo <bar>` <baz>

But, what if I *really* wanted to remove that space? Is there some
rule against doing that?

2010/9/7 Fernando Gómez <fjg...@gmail.com>:

Daniel Neuhäuser

unread,
Sep 7, 2010, 5:35:50 PM9/7/10
to sphin...@googlegroups.com
> But, what if I *really* wanted to remove that space? Is there some
> rule against doing that?
Yeah there is, inline markup can't be used in words like *foo*bar. Try
escaping the opening bracket like :ref:`foo <bar>`\<baz>.

However this shouldn't raise an exception like this but that is a
problem with docutils.

Max Battcher

unread,
Sep 7, 2010, 6:43:44 PM9/7/10
to sphin...@googlegroups.com
On 9/7/2010 17:35, Daniel Neuh�user wrote:
>> But, what if I *really* wanted to remove that space? Is there some
>> rule against doing that?
> Yeah there is, inline markup can't be used in words like *foo*bar. Try
> escaping the opening bracket like :ref:`foo<bar>`\<baz>.

YMMV, but often the cleanest looking version is:

:ref:`foo<bar>`\ <baz>

The escaped space will not be output, but makes a clear separation
between the markup.

> However this shouldn't raise an exception like this but that is a
> problem with docutils.

No, I believe it should, to remain consistent with the aforementioned
case (*foo*bar) and several other examples besides that one (which
docutils, for instance, lumps under the name "character-level inline
markup").

The relevant documentation:

http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#inline-markup

Particularly, the small immediately following subsection:

http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#character-level-inline-markup

Also:

http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#escaping-mechanism

--
--Max Battcher--
http://worldmaker.net

Daniel Neuhäuser

unread,
Sep 7, 2010, 7:37:14 PM9/7/10
to sphin...@googlegroups.com
> No, I believe it should, to remain consistent with the aforementioned
> case (*foo*bar) and several other examples besides that one (which
> docutils, for instance, lumps under the name "character-level inline
> markup").
Well obviously there should be an exception, however it should be clear
by the message of that exception what is going wrong. Unless you know
about these details of restructured Text it's impossible to tell what is
going wrong here and even then a lot of people will probably assume that
an exception with a clearly understandable message is being raised and
still wonder what is happening.

Guenter Milde

unread,
Sep 8, 2010, 2:27:16 AM9/8/10
to sphin...@googlegroups.com
On 2010-09-07, Daniel =?ISO-8859-1?Q?Neuh=E4user?= wrote:
>> No, I believe it should, to remain consistent with the aforementioned
>> case (*foo*bar) and several other examples besides that one (which
>> docutils, for instance, lumps under the name "character-level inline
>> markup").

> Well obviously there should be an exception, however it should be clear
> by the message of that exception what is going wrong.

There were several problems with the error output in older Docutils
versions.

It works OK with the development version under Python 2.6 here:

testrole.txt::

Define the ``ref`` role for docutils:

.. role:: ref

The offending reST (simplified):



:ref:`foo <bar>`<baz>

Adding whitespace after the closing backquotes solves the issue:

:ref:`foo <bar>` <baz>

As does:

:ref:`foo <bar>`\<baz>

:ref:`foo <bar>`\ <baz>

which do not show the space in the output.

Running::

rst2html.py testrole.txt testrole.html

I get the expected message::

testrole.txt:5: (WARNING/2) Inline interpreted text or phrase reference
start-string without end-string.


Could you check the Docutils version (``rst2html.py --version``) and check
with Docutils.

If this fails, maybe upgrade Docutils to either the latest release or a
daily snapshot?

Günter

Daniel Neuhäuser

unread,
Sep 8, 2010, 3:59:09 AM9/8/10
to sphin...@googlegroups.com
It works as expected with a recent docutils version.

Reply all
Reply to author
Forward
0 new messages