mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-21 00:19:42 +02:00
remove more type hinting for python 3.6
This commit is contained in:
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
# from __future__ import annotations
|
# from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Iterable
|
from collections import namedtuple
|
||||||
import string
|
import string
|
||||||
from types import MappingProxyType
|
# from types import MappingProxyType
|
||||||
from typing import Any, BinaryIO, NamedTuple
|
# from typing import Any, BinaryIO, NamedTuple
|
||||||
|
|
||||||
from ._re import (
|
from ._re import (
|
||||||
RE_DATETIME,
|
RE_DATETIME,
|
||||||
@ -37,8 +37,7 @@ BARE_KEY_CHARS = frozenset(string.ascii_letters + string.digits + "-_")
|
|||||||
KEY_INITIAL_CHARS = BARE_KEY_CHARS | frozenset("\"'")
|
KEY_INITIAL_CHARS = BARE_KEY_CHARS | frozenset("\"'")
|
||||||
HEXDIGIT_CHARS = frozenset(string.hexdigits)
|
HEXDIGIT_CHARS = frozenset(string.hexdigits)
|
||||||
|
|
||||||
BASIC_STR_ESCAPE_REPLACEMENTS = MappingProxyType(
|
BASIC_STR_ESCAPE_REPLACEMENTS = {
|
||||||
{
|
|
||||||
"\\b": "\u0008", # backspace
|
"\\b": "\u0008", # backspace
|
||||||
"\\t": "\u0009", # tab
|
"\\t": "\u0009", # tab
|
||||||
"\\n": "\u000A", # linefeed
|
"\\n": "\u000A", # linefeed
|
||||||
@ -46,8 +45,7 @@ BASIC_STR_ESCAPE_REPLACEMENTS = MappingProxyType(
|
|||||||
"\\r": "\u000D", # carriage return
|
"\\r": "\u000D", # carriage return
|
||||||
'\\"': "\u0022", # quote
|
'\\"': "\u0022", # quote
|
||||||
"\\\\": "\u005C", # backslash
|
"\\\\": "\u005C", # backslash
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TOMLDecodeError(ValueError):
|
class TOMLDecodeError(ValueError):
|
||||||
@ -191,9 +189,9 @@ class Flags:
|
|||||||
|
|
||||||
|
|
||||||
class NestedDict:
|
class NestedDict:
|
||||||
def __init__(self) -> None:
|
def __init__(self):
|
||||||
# The parsed content of the TOML document
|
# The parsed content of the TOML document
|
||||||
self.dict: dict[str, Any] = {}
|
self.dict = {}
|
||||||
|
|
||||||
def get_or_create_nest(
|
def get_or_create_nest(
|
||||||
self,
|
self,
|
||||||
@ -201,7 +199,7 @@ class NestedDict:
|
|||||||
*,
|
*,
|
||||||
access_lists: bool = True,
|
access_lists: bool = True,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
cont: Any = self.dict
|
cont = self.dict
|
||||||
for k in key:
|
for k in key:
|
||||||
if k not in cont:
|
if k not in cont:
|
||||||
cont[k] = {}
|
cont[k] = {}
|
||||||
@ -224,9 +222,11 @@ class NestedDict:
|
|||||||
cont[last_key] = [{}]
|
cont[last_key] = [{}]
|
||||||
|
|
||||||
|
|
||||||
class Output(NamedTuple):
|
# class Output(namedtuple):
|
||||||
data: NestedDict
|
# data: NestedDict
|
||||||
flags: Flags
|
# flags: Flags
|
||||||
|
|
||||||
|
Output = namedtuple('Output', ['data', 'flags'])
|
||||||
|
|
||||||
|
|
||||||
def skip_chars(src: str, pos, chars):
|
def skip_chars(src: str, pos, chars):
|
||||||
@ -682,7 +682,7 @@ def make_safe_parse_float(parse_float):
|
|||||||
if parse_float is float:
|
if parse_float is float:
|
||||||
return float
|
return float
|
||||||
|
|
||||||
def safe_parse_float(float_str: str) -> Any:
|
def safe_parse_float(float_str):
|
||||||
float_value = parse_float(float_str)
|
float_value = parse_float(float_str)
|
||||||
if isinstance(float_value, (dict, list)):
|
if isinstance(float_value, (dict, list)):
|
||||||
raise ValueError("parse_float must not return dicts or lists")
|
raise ValueError("parse_float must not return dicts or lists")
|
||||||
|
Reference in New Issue
Block a user