Skip to content

Pylint crashes with "'\U00010000' == '\ud800\udc00'" #8736

@xiaxinmeng

Description

@xiaxinmeng

The following code cause pylint crashing with a UnicodeEncodeError.

pylint_example.py:
assert "\U00010000" == "\ud800\udc00"

The expected behavior:

This code can work normally.

The actual output:

>> pylint pylint_example.py
************* Module pylint_example
Desktop/pylint_example.py:10:8: C0303: Trailing whitespace (trailing-whitespace)
Desktop/pylint_example.py:11:0: C0304: Final newline missing (missing-final-newline)
Desktop/pylint_example.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Desktoppylint_example.py:11:0: W0104: Statement seems to have no effect (pointless-statement)
Exception on node <Compare l.11 at 0x7f13363f0750> in file '/home/xxm/Desktop/pylint_example.py'
Traceback (most recent call last):
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 91, in walk
    callback(astroid)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/base/comparison_checker.py", line 301, in visit_compare
    self._check_constants_comparison(node)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/base/comparison_checker.py", line 258, in _check_constants_comparison
    self.add_message(
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/checkers/base_checker.py", line 152, in add_message
    self.linter.add_message(
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1257, in add_message
    self._add_one_message(
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/lint/pylinter.py", line 1215, in _add_one_message
    self.reporter.handle_message(
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/reporters/text.py", line 161, in handle_message
    self.write_message(msg)
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/reporters/text.py", line 154, in write_message
    self.writeln(self._fixed_template.format(**self_dict))
  File "/home/xxm/.local/lib/python3.11/site-packages/pylint/reporters/base_reporter.py", line 45, in writeln
    print(string, file=self.out)
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 109-110: surrogates not allowed
Desktop/pylint_example.py:1:0: F0002: /home/xxm/Desktop/pylint_example.py: Fatal error while checking '/home/xxm/Desktop/pylint_example.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/xxm/.cache/pylint/pylint-crash-2023-06-06-16-17-51.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Test Environment:

Ubuntu 18.04,
CPython 3.11.3
Pylint: 3.0.0b1
astroid 3.0.0a3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions