Skip to content

Commit 853a3df

Browse files
[performance] Use modern named tuple instead of 'exec' definition
The init needs to analyse a string with the old way of doing things, which is not the best in term of performance.
1 parent 3c180df commit 853a3df

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pylint/interfaces.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from __future__ import annotations
88

99
import warnings
10-
from collections import namedtuple
1110
from tokenize import TokenInfo
12-
from typing import TYPE_CHECKING
11+
from typing import TYPE_CHECKING, NamedTuple
1312

1413
from astroid import nodes
1514

@@ -33,7 +32,12 @@
3332
"CONFIDENCE_LEVEL_NAMES",
3433
)
3534

36-
Confidence = namedtuple("Confidence", ["name", "description"])
35+
36+
class Confidence(NamedTuple):
37+
name: str
38+
description: str
39+
40+
3741
# Warning Certainties
3842
HIGH = Confidence("HIGH", "Warning that is not based on inference result.")
3943
CONTROL_FLOW = Confidence(

pylint/utils/pragma_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from __future__ import annotations
66

77
import re
8-
from collections import namedtuple
98
from collections.abc import Generator
9+
from typing import NamedTuple
1010

1111
# Allow stopping after the first semicolon/hash encountered,
1212
# so that an option can be continued with the reasons
@@ -27,7 +27,9 @@
2727
OPTION_PO = re.compile(OPTION_RGX, re.VERBOSE)
2828

2929

30-
PragmaRepresenter = namedtuple("PragmaRepresenter", "action messages")
30+
class PragmaRepresenter(NamedTuple):
31+
action: str
32+
messages: list[str]
3133

3234

3335
ATOMIC_KEYWORDS = frozenset(("disable-all", "skip-file"))

0 commit comments

Comments
 (0)