Skip to content

Monkeypatching html.parser fails when importing with zipimporter #1132

Open
@remyroy

Description

@remyroy

When trying to monkeypatch a copy of html.parser, markdown fails when html.parser comes from a zip file and an instance of zipimporter is used as the loader.

To reproduce

  1. Download an embeddable package version of Python like the latest Windows embeddable package (64-bit) (Python 3.9.5)
  2. Unzip it
  3. Copy the markdown package into the python folder
  4. Run python
  5. Import markdown
  6. Notice the following traceback:
$ python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
>>> import markdown
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Rémy Roy\Projects\CDDA-Game-Launcher\build\test\markdown\__init__.py", line 29, in <module>
    from .core import Markdown, markdown, markdownFromFile  # noqa: E402
  File "C:\Users\Rémy Roy\Projects\CDDA-Game-Launcher\build\test\markdown\core.py", line 27, in <module>
    from .preprocessors import build_preprocessors
  File "C:\Users\Rémy Roy\Projects\CDDA-Game-Launcher\build\test\markdown\preprocessors.py", line 29, in <module>
    from .htmlparser import HTMLExtractor
  File "C:\Users\Rémy Roy\Projects\CDDA-Game-Launcher\build\test\markdown\htmlparser.py", line 31, in <module>
    spec.loader.exec_module(htmlparser)
AttributeError: 'zipimporter' object has no attribute 'exec_module'

The main issue is that the zipimporter loader does not have an exec_module method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report.coreRelated to the core parser code.someday-maybeApproved low priority request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions