Skip to content

Commit 8d4e624

Browse files
committed
Configure ruff beyond the basics
Especially isort, shame it's not part of format but...
1 parent 7da56fd commit 8d4e624

17 files changed

Lines changed: 60 additions & 47 deletions

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ classifiers = [
4343
"Programming Language :: Python :: Implementation :: PyPy"
4444
]
4545

46+
[tool.ruff.lint]
47+
select = ["F", "E", "W", "I", "RET", "RUF", "PT"]
48+
ignore = [
49+
"RET505", # elif after return
50+
"E501", # line too long, formatter should take care of the fixable ones
51+
]
52+
53+
[tool.ruff.lint.isort]
54+
classes = ["LRU", "OS"]
55+
combine-as-imports = true
56+
4657
[tool.mypy]
4758
python_version = "3.8"
4859
files = "src,tests"

src/ua_parser/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import contextlib
4949
from typing import Callable, Optional
5050

51+
from .basic import Parser as BasicParser
52+
from .caching import CachingParser, Clearing, Locking, LRU
5153
from .core import (
5254
DefaultedParseResult,
5355
Device,
@@ -56,15 +58,13 @@
5658
Matchers,
5759
OS,
5860
OSMatcher,
59-
ParseResult,
6061
Parser,
62+
ParseResult,
6163
PartialParseResult,
6264
UserAgent,
6365
UserAgentMatcher,
6466
)
65-
from .basic import Parser as BasicParser
66-
from .caching import CachingParser, Clearing, LRU, Locking
67-
from .loaders import load_builtins, load_lazy_builtins, load_data, load_yaml
67+
from .loaders import load_builtins, load_data, load_lazy_builtins, load_yaml
6868

6969
Re2Parser: Optional[Callable[[Matchers], Parser]] = None
7070
with contextlib.suppress(ImportError):

src/ua_parser/_lazy.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__all__ = ["MATCHERS"]
22

3-
from typing import Tuple, List
4-
from .lazy import UserAgentMatcher, OSMatcher, DeviceMatcher
3+
from typing import List, Tuple
4+
5+
from .lazy import DeviceMatcher, OSMatcher, UserAgentMatcher
56

67
MATCHERS: Tuple[
78
List[UserAgentMatcher],

src/ua_parser/_matchers.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__all__ = ["MATCHERS"]
22

3-
from typing import Tuple, List
4-
from .core import UserAgentMatcher, OSMatcher, DeviceMatcher
3+
from typing import List, Tuple
4+
5+
from .core import DeviceMatcher, OSMatcher, UserAgentMatcher
56

67
MATCHERS: Tuple[
78
List[UserAgentMatcher],

src/ua_parser/_regexes.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import List
2-
from .user_agent_parser import UserAgentParser, OSParser, DeviceParser
2+
3+
from .user_agent_parser import DeviceParser, OSParser, UserAgentParser
34

45
USER_AGENT_PARSERS: List[UserAgentParser]
56
OS_PARSERS: List[OSParser]

src/ua_parser/bench.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import argparse
22
import csv
3-
import itertools
43
import io
5-
import time
4+
import itertools
65
import sys
6+
import time
77
from typing import Any, Callable, Iterable, List, Optional
88

99
from . import (
10-
load_builtins,
11-
load_yaml,
1210
BasicParser,
1311
CachingParser,
1412
Clearing,
15-
LRU,
1613
Locking,
14+
LRU,
1715
Matchers,
1816
Parser,
17+
load_builtins,
18+
load_yaml,
1919
)
2020
from .caching import Cache
21-
from .user_agent_parser import Parse
2221
from .re2 import Parser as Re2Parser
22+
from .user_agent_parser import Parse
2323

2424
CACHEABLE = {
2525
"basic": True,

src/ua_parser/caching.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import abc
2-
from collections import OrderedDict
32
import threading
3+
from collections import OrderedDict
44
from typing import Dict, Optional
55

6-
from .core import Parser, Domain, PartialParseResult
7-
6+
from .core import Domain, Parser, PartialParseResult
87

98
__all__ = [
109
"CachingParser",

src/ua_parser/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from dataclasses import dataclass
44
from enum import Flag, auto
5-
from typing import Generic, Literal, Optional, Tuple, List, TypeVar, Match, Pattern
5+
from typing import Generic, List, Literal, Match, Optional, Pattern, Tuple, TypeVar
66

77
__all__ = [
88
"DefaultedParseResult",

src/ua_parser/lazy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from functools import cached_property
55
from typing import Literal, Optional, Pattern
66

7-
from .core import Matcher, UserAgent, OS, Device, _replacer, _get
7+
from .core import Device, Matcher, OS, UserAgent, _get, _replacer
88

99

1010
class UserAgentMatcher(Matcher[UserAgent]):

src/ua_parser/loaders.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
import os
1717
from typing import (
18+
TYPE_CHECKING,
1819
Callable,
1920
List,
2021
Literal,
@@ -24,21 +25,20 @@
2425
Type,
2526
TypedDict,
2627
Union,
27-
TYPE_CHECKING,
2828
cast,
2929
)
3030

3131
from . import lazy
32-
from .core import Matchers, UserAgentMatcher, OSMatcher, DeviceMatcher
32+
from .core import DeviceMatcher, Matchers, OSMatcher, UserAgentMatcher
3333

3434
if TYPE_CHECKING:
3535
PathOrFile = Union[str, os.PathLike[str], io.IOBase]
3636
SafeLoader: Optional[Type[object]]
3737
try:
38-
from yaml import load, CSafeLoader as SafeLoader
38+
from yaml import CSafeLoader as SafeLoader, load
3939
except ImportError:
4040
try:
41-
from yaml import load, SafeLoader
41+
from yaml import SafeLoader, load
4242
except ImportError:
4343
load = SafeLoader = None # type: ignore
4444

0 commit comments

Comments
 (0)