question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: malformed node or string

See original GitHub issue

Hi! I am running pydocstyle as a part of flake8-docstrings plugin which is a plugin for wemake-python-styleguide.

Original issue: https://github.com/wemake-services/wemake-python-styleguide/issues/579

One of my users reported this bug:

multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/checker.py", line 669, in _run_checks
return checker.run_checks()
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/checker.py", line 608, in run_checks
self.run_ast_checks()
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/checker.py", line 504, in run_ast_checks
for (line_number, offset, text, check) in runner:
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8_docstrings.py", line 89, in run
for error in self._check_source():
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8_docstrings.py", line 78, in _check_source
ignore_decorators=None,
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/pydocstyle/checker.py", line 75, in check_source
definition.docstring)
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/pydocstyle/checker.py", line 114, in check_docstring_missing
docstring and is_blank(ast.literal_eval(docstring))):
File "/usr/lib/python3.7/ast.py", line 91, in literal_eval
return _convert(node_or_string)
File "/usr/lib/python3.7/ast.py", line 90, in _convert
return _convert_signed_num(node)
File "/usr/lib/python3.7/ast.py", line 63, in _convert_signed_num
return _convert_num(node)
File "/usr/lib/python3.7/ast.py", line 55, in _convert_num
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.JoinedStr object at 0x7f1d8db27358>
"""

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

Traceback (most recent call last):
File "/home/ilya/.virtualenvs/ds-backend/bin/flake8", line 10, in 
sys.exit(main())
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/main/cli.py", line 18, in main
app.run(argv)
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/main/application.py", line 394, in run
self._run(argv)
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/main/application.py", line 382, in _run
self.run_checks()
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/main/application.py", line 301, in run_checks
self.file_checker_manager.run()
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/checker.py", line 328, in run
self.run_parallel()
File "/home/ilya/.virtualenvs/ds-backend/lib/python3.7/site-packages/flake8/checker.py", line 292, in run_parallel
for ret in pool_map:
File "/usr/lib/python3.7/multiprocessing/pool.py", line 354, in 
return (item for chunk in result for item in chunk)
File "/usr/lib/python3.7/multiprocessing/pool.py", line 748, in next
raise value
ValueError: malformed node or string: <_ast.JoinedStr object at 0x7f1d8db27358>

This happens here: https://github.com/PyCQA/pydocstyle/blob/master/src/pydocstyle/checker.py#L159

Reproduction code:

def function():
    f"""Template #{locals}"""
    ...

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
bra-fsncommented, Aug 13, 2020

Any progress on this? It’s quite puzzling to run into this, because there’s no indication on what/where the error is, just a big fat python backtrace.

3reactions
sobolevncommented, Jul 14, 2019

I would say that something like this should be done:

def safe_literal_eval(node) -> Optional[str]:
     try:
         return ast.literal_eval(node)
     except ValueError:
         return None  # happens when literal eval cannot process node

And then check that instead of ast.literal_eval this function is used and None value is checked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: malformed node or string - python - Stack Overflow
It is possible to crash the Python interpreter with a sufficiently large/complex string due to stack depth limitations in Python's AST compiler.
Read more >
ValueError malformed string when using ast literal eval
However In python 2.7 it returns ValueError: malformed string when running ... USub: operator.neg } node = ast.parse(s, mode='eval') def ...
Read more >
Malformed node or string error from NN classifier - Edge Impulse
Hello Edgy Impulsers :slight_smile: I little bit of background: I am using EI for an entomology project. As a trial, I labelled some...
Read more >
malformed node or string error when parsing lists from a text file
ValueError : malformed node or string: <_ast.Subscript object at 0x03C72BB0>. How can I convert my text file into the format I want? score:0....
Read more >
is an f-sting not a literal? - Python Forum
raise ValueError( f 'malformed node or string: {node!r}' ). ValueError: malformed node or string: <_ast.JoinedStr object at 0x7f939adfda00 > ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found