Skip to content

Commit

Permalink
First pre-commit swipe (isort, flake8-bugbear, black, pyupgrade)
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Jul 18, 2022
1 parent fb70739 commit 60abdac
Show file tree
Hide file tree
Showing 24 changed files with 213 additions and 199 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ repos:
- id: pyupgrade
args: [--py36-plus]

- repo: https://github.com/hadialqattan/pycln
rev: v2.0.1
hooks:
- id: pycln
args: [--all]
# - repo: https://github.com/hadialqattan/pycln
# rev: v2.0.1
# hooks:
# - id: pycln
# args: [--all]

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import io
import json
import os
Expand Down
2 changes: 2 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime

from tomlkit import aot
Expand Down
4 changes: 3 additions & 1 deletion tests/test_items.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import math
import pickle

Expand Down Expand Up @@ -120,7 +122,7 @@ def test_aot_unwrap():
d = item([{"a": "A"}, {"b": "B"}])
unwrapped = d.unwrap()
assert_is_ppo(unwrapped, list)
for du, dw in zip(unwrapped, d):
for du, _dw in zip(unwrapped, d):
assert_is_ppo(du, dict)
for ku in du:
vu = du[ku]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import pytest

from tomlkit.exceptions import EmptyTableNameError
Expand Down
2 changes: 2 additions & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import copy
import json
import pickle
Expand Down
2 changes: 2 additions & 0 deletions tests/test_toml_file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os

from tomlkit.toml_document import TOMLDocument
Expand Down
2 changes: 2 additions & 0 deletions tests/test_toml_spec_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import os
import re
Expand Down
2 changes: 2 additions & 0 deletions tests/test_toml_tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json

import pytest
Expand Down
2 changes: 2 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import date
from datetime import datetime as dt
from datetime import time
Expand Down
2 changes: 2 additions & 0 deletions tests/test_write.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from tomlkit import dumps
from tomlkit import loads

Expand Down
4 changes: 3 additions & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from tomlkit.items import AoT
from tomlkit.items import Array
from tomlkit.items import Bool
Expand Down Expand Up @@ -43,7 +45,7 @@


def assert_not_tomlkit_type(v):
for i, T in enumerate(TOMLKIT_TYPES):
for _, T in enumerate(TOMLKIT_TYPES):
assert not isinstance(v, T)


Expand Down
6 changes: 3 additions & 3 deletions tomlkit/_compat.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

import sys

from typing import Any
from typing import List
from typing import Optional


PY38 = sys.version_info >= (3, 8)


def decode(string: Any, encodings: Optional[List[str]] = None):
def decode(string: Any, encodings: list[str] | None = None):
if not isinstance(string, bytes):
return string

Expand Down
8 changes: 4 additions & 4 deletions tomlkit/_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import re

from collections.abc import Mapping
Expand All @@ -7,7 +9,6 @@
from datetime import timedelta
from datetime import timezone
from typing import Collection
from typing import Union

from ._compat import decode

Expand Down Expand Up @@ -41,7 +42,7 @@
_utc = timezone(timedelta(), "UTC")


def parse_rfc3339(string: str) -> Union[datetime, date, time]:
def parse_rfc3339(string: str) -> datetime | date | time:
m = RFC_3339_DATETIME.match(string)
if m:
year = int(m.group(1))
Expand Down Expand Up @@ -125,7 +126,6 @@ def escape_string(s: str, escape_sequences: Collection[str] = _basic_escapes) ->

res = []
start = 0
l = len(s)

def flush(inc=1):
if start != i:
Expand All @@ -134,7 +134,7 @@ def flush(inc=1):
return i + inc

i = 0
while i < l:
while i < len(s):
for seq in escape_sequences:
seq_len = len(seq)
if s[i:].startswith(seq):
Expand Down
16 changes: 8 additions & 8 deletions tomlkit/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations

import datetime as _datetime

from collections.abc import Mapping
from typing import IO
from typing import Iterable
from typing import Tuple
from typing import Union

from ._utils import parse_rfc3339
from .container import Container
Expand Down Expand Up @@ -33,7 +33,7 @@
from .toml_document import TOMLDocument


def loads(string: Union[str, bytes]) -> TOMLDocument:
def loads(string: str | bytes) -> TOMLDocument:
"""
Parses a string into a TOMLDocument.
Expand Down Expand Up @@ -75,7 +75,7 @@ def dump(data: Mapping, fp: IO[str], *, sort_keys: bool = False) -> None:
fp.write(dumps(data, sort_keys=sort_keys))


def parse(string: Union[str, bytes]) -> TOMLDocument:
def parse(string: str | bytes) -> TOMLDocument:
"""
Parses a string or bytes into a TOMLDocument.
"""
Expand All @@ -90,12 +90,12 @@ def document() -> TOMLDocument:


# Items
def integer(raw: Union[str, int]) -> Integer:
def integer(raw: str | int) -> Integer:
"""Create an integer item from a number or string."""
return item(int(raw))


def float_(raw: Union[str, float]) -> Float:
def float_(raw: str | float) -> Float:
"""Create an float item from a number or string."""
return item(float(raw))

Expand Down Expand Up @@ -223,7 +223,7 @@ def aot() -> AoT:
return AoT([])


def key(k: Union[str, Iterable[str]]) -> Key:
def key(k: str | Iterable[str]) -> Key:
"""Create a key from a string. When a list of string is given,
it will create a dotted key.
Expand Down Expand Up @@ -260,7 +260,7 @@ def value(raw: str) -> _Item:
return v


def key_value(src: str) -> Tuple[Key, _Item]:
def key_value(src: str) -> tuple[Key, _Item]:
"""Parse a key-value pair from a string.
:Example:
Expand Down
Loading

0 comments on commit 60abdac

Please sign in to comment.