Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/libcst/_parser/types/py_config.py: 95%
22 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:43 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-25 06:43 +0000
1# Copyright (c) Meta Platforms, Inc. and affiliates.
2#
3# This source code is licensed under the MIT license found in the
4# LICENSE file in the root directory of this source tree.
6import abc
7from dataclasses import asdict, dataclass
8from typing import Any, FrozenSet, Mapping, Sequence
10from libcst._parser.parso.utils import PythonVersionInfo
13class BaseWhitespaceParserConfig(abc.ABC):
14 """
15 Represents the subset of ParserConfig that the whitespace parser requires. This
16 makes calling the whitespace parser in tests with a mocked configuration easier.
17 """
19 lines: Sequence[str]
20 default_newline: str
23@dataclass(frozen=True)
24class MockWhitespaceParserConfig(BaseWhitespaceParserConfig):
25 """
26 An internal type used by unit tests.
27 """
29 lines: Sequence[str]
30 default_newline: str
33@dataclass(frozen=True)
34class ParserConfig(BaseWhitespaceParserConfig):
35 """
36 An internal configuration object that the python parser passes around. These
37 values are global to the parsed code and should not change during the lifetime
38 of the parser object.
39 """
41 lines: Sequence[str]
42 encoding: str
43 default_indent: str
44 default_newline: str
45 has_trailing_newline: bool
46 version: PythonVersionInfo
47 future_imports: FrozenSet[str]
50def parser_config_asdict(config: ParserConfig) -> Mapping[str, Any]:
51 """
52 An internal helper function used by unit tests to compare configs.
53 """
54 return asdict(config)