diff options
| author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2023-02-12 16:58:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-12 16:58:42 +0000 |
| commit | 4af956c9115fe8912fa4ee8799c6e5aedd2f6c96 (patch) | |
| tree | 0b1c14f52a85385576bb9b5d6a4a34dc4fa2c82c /tests | |
| parent | c47d3b95a1dd173fb44fdba2d8dcc46eb88559a9 (diff) | |
| download | astroid-git-4af956c9115fe8912fa4ee8799c6e5aedd2f6c96.tar.gz | |
Fix '_infer_str_format_call' crash when the string it analyses are uninferable (#2024) (#2025)
Closes PyCQA/pylint#8109
(cherry picked from commit ccbdd3c128af9a6e8f9018fb8db5991a28c72db0)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_brain_builtin.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/unittest_brain_builtin.py b/tests/unittest_brain_builtin.py index d14c72f8..a1439b06 100644 --- a/tests/unittest_brain_builtin.py +++ b/tests/unittest_brain_builtin.py @@ -9,7 +9,7 @@ import unittest import pytest from astroid import nodes, objects, util -from astroid.builder import _extract_single_node +from astroid.builder import _extract_single_node, extract_node class BuiltinsTest(unittest.TestCase): @@ -127,3 +127,22 @@ class TestStringNodes: inferred = next(node.infer()) assert isinstance(inferred, nodes.Const) assert inferred.value == "My name is Daniel, I'm 12.00" + + def test_string_format_in_dataclass_pylint8109(self) -> None: + """https://github.com/PyCQA/pylint/issues/8109""" + function_def = extract_node( + """ +from dataclasses import dataclass + +@dataclass +class Number: + amount: int | float + round: int = 2 + + def __str__(self): #@ + number_format = "{:,.%sf}" % self.round + return number_format.format(self.amount).rstrip("0").rstrip(".") +""" + ) + inferit = function_def.infer_call_result(function_def, context=None) + assert [a.name for a in inferit] == [util.Uninferable] |
