Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace dataclass with SimpleNamespace.
Reduces import time by over 50% (10431µs vs 4350µs on Apple M3 Pro).
  • Loading branch information
jaraco committed Apr 10, 2024
commit 7de4e0045b9d6574492291be07ef21a5171e2787
18 changes: 11 additions & 7 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@
between keys and values are surrounded by spaces.
"""

# Do not import dataclasses; overhead is unacceptable (gh-117703)

from collections.abc import Iterable, MutableMapping
from collections import ChainMap as _ChainMap
import contextlib
from dataclasses import dataclass, field
import functools
import io
import itertools
import os
import re
import sys
import types

__all__ = ("NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
"NoOptionError", "InterpolationError", "InterpolationDepthError",
Expand Down Expand Up @@ -537,19 +539,21 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,
"found: %r" % (rest,))


@dataclass
class _ReadState:
elements_added : set[str] = field(default_factory=set)
class _ReadState(types.SimpleNamespace):
elements_added : set[str]
cursect : dict[str, str] | None = None
sectname : str | None = None
optname : str | None = None
lineno : int = 0
indent_level : int = 0
errors : list[ParsingError] = field(default_factory=list)
errors : list[ParsingError]

def __init__(self):
self.elements_added = set()
self.errors = list()


@dataclass
class _Prefixes:
class _Prefixes(types.SimpleNamespace):
full : Iterable[str]
inline : Iterable[str]

Expand Down