Skip to content

Shadowing version in conf.py with an import causes an error in intersphinx #13879

@JannisNe

Description

@JannisNe

Describe the bug

While building the documentation sphinx errors with a TypeError. It looks like it is trying to parse a string with re that is not properly converted to str before.

# Platform:         darwin; (macOS-15.3.2-arm64-arm-64bit)
# Sphinx version:   7.3.7
# Python version:   3.10.9 (CPython)
# Docutils version: 0.18.1
# Jinja2 version:   3.1.2
# Pygments version: 2.16.1

# Last messages:
#   dumping object inventory...
#   failed
#   [app] emitting event: 'build-finished'(TypeError('expected string or bytes-like object'),)
#   
#   ====================== slowest reading durations =======================
#   0.280 api
#   0.246 generated/timewise.wise_bigdata_desy_cluster.WISEDataDESYCluster
#   0.142 generated/timewise.wise_data_by_visit.WiseDataByVisit
#   0.129 generated/timewise.wise_data_base.WISEDataBase
#   0.022 generated/timewise.parent_sample_base.ParentSampleBase

# Loaded extensions:
#   sphinx.ext.mathjax (7.3.7)
#   alabaster (0.7.16)
#   sphinxcontrib.applehelp (1.0.4)
#   sphinxcontrib.devhelp (1.0.2)
#   sphinxcontrib.htmlhelp (2.0.1)
#   sphinxcontrib.serializinghtml (2.0.0)
#   sphinxcontrib.qthelp (1.0.3)
#   sphinx.ext.duration (7.3.7)
#   sphinx.ext.doctest (7.3.7)
#   sphinx.ext.autodoc.preserve_defaults (7.3.7)
#   sphinx.ext.autodoc.type_comment (7.3.7)
#   sphinx.ext.autodoc.typehints (7.3.7)
#   sphinx.ext.autodoc (7.3.7)
#   sphinx.ext.autosummary (7.3.7)
#   sphinx.ext.viewcode (7.3.7)
#   myst_parser (2.0.0)

# Traceback:
Traceback (most recent call last):
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/cmd/build.py", line 337, in build_main
    app.build(args.force_all, args.filenames)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/application.py", line 349, in build
    self.builder.build_specific(filenames)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 281, in build_specific
    self.build(docnames, method='specific',
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 365, in build
    self.finish()
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 682, in finish
    self.handle_finish()
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 1152, in handle_finish
    self.finish_tasks.add_task(self.dump_inventory)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/util/parallel.py", line 41, in add_task
    res = task_func()
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/util/display.py", line 93, in wrapper
    return f(*args, **kwargs)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/builders/html/__init__.py", line 1156, in dump_inventory
    InventoryFile.dump(path.join(self.outdir, INVENTORY_FILENAME), self.env, self)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/util/inventory.py", line 171, in dump
    escape(env.config.version))).encode())
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/site-packages/sphinx/util/inventory.py", line 162, in escape
    return re.sub("\\s+", " ", string)
  File "/Users/jannisnecker/opt/miniconda3/envs/timewise/lib/python3.10/re.py", line 209, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object

How to Reproduce

Unfortunately, I can not tell which part of the documentation is trying to be parsed so I do not know how to make a minimal example. I can only reference my package:

git clone https://github.com/JannisNe/timewise.git
cd timewise
python -m sphinx docs/source -T -b html -d _build/doctrees -D language=en . ./html -c docs/source/

Environment Information

Platform:              darwin; (macOS-15.3.2-arm64-arm-64bit)
Python version:        3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:26:08) [Clang 14.0.6 ])
Python implementation: CPython
Sphinx version:        7.3.7
Docutils version:      0.18.1
Jinja2 version:        3.1.2
Pygments version:      2.16.1

Sphinx extensions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions