Skip to content

Commit 007dc90

Browse files
committed
Further de-linting
1 parent f21b26b commit 007dc90

15 files changed

+72
-32
lines changed

.pre-commit-config.yaml

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.4.0
5+
rev: v4.5.0
66
hooks:
77
- id: check-added-large-files
88
- id: check-merge-conflict
9+
- id: check-executables-have-shebangs
10+
- id: check-shebang-scripts-are-executable
11+
- id: end-of-file-fixer
912
- repo: https://github.com/asottile/pyupgrade
10-
rev: v3.3.1
13+
rev: v3.15.0
1114
hooks:
1215
- id: pyupgrade
1316
args:
1417
- "--py39-plus"
15-
- repo: https://github.com/psf/black
16-
rev: 23.1.0
18+
- repo: https://github.com/psf/black-pre-commit-mirror
19+
rev: 23.12.1
1720
hooks:
1821
- id: black
1922
- repo: https://github.com/PyCQA/isort
20-
rev: 5.12.0
23+
rev: 5.13.2
2124
hooks:
2225
- id: isort
2326
- repo: https://github.com/PyCQA/flake8
24-
rev: 6.0.0
27+
rev: 6.1.0
2528
hooks:
2629
- id: flake8
2730
additional_dependencies:
31+
- flake8-absolute-import
2832
- flake8-annotations
2933
- flake8-builtins
3034
- flake8-comprehensions
@@ -37,7 +41,7 @@ repos:
3741
- flake8-use-fstring
3842
- flake8-use-pathlib
3943
- repo: https://github.com/pre-commit/mirrors-prettier
40-
rev: v3.0.0-alpha.4
44+
rev: v3.1.0
4145
hooks:
4246
- id: prettier
4347
args:

.vscode/extensions.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"ms-python.black-formatter",
5+
"ms-python.flake8",
6+
"ms-python.isort",
7+
"ms-python.python",
8+
"ms-python.vscode-pylance"
9+
]
10+
}

.vscode/settings.json

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
2-
"python.linting.pylintEnabled": false,
3-
"python.linting.flake8Enabled": true,
4-
"python.linting.enabled": true,
52
"editor.formatOnSave": true,
6-
"python.formatting.provider": "black",
73
"python.testing.pytestArgs": ["tests"],
84
"python.testing.pytestEnabled": true,
9-
"git.rebaseWhenSync": true
5+
"git.rebaseWhenSync": true,
6+
"[json]": {
7+
"editor.defaultFormatter": "esbenp.prettier-vscode"
8+
},
9+
"[python]": {
10+
"editor.defaultFormatter": "ms-python.black-formatter",
11+
"editor.codeActionsOnSave": {
12+
"source.organizeImports": "explicit"
13+
}
14+
},
15+
"window.title": "${dirty}${rootName}${separator}${activeEditorShort}"
1016
}

mtgproxies/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mtgproxies.decklists.decklist import Decklist
55

66

7-
def parse_decklist_spec(decklist_spec: str, warn_levels=["ERROR", "WARNING", "COSMETIC"]) -> Decklist:
7+
def parse_decklist_spec(decklist_spec: str, warn_levels=("ERROR", "WARNING", "COSMETIC")) -> Decklist:
88
"""Attempt to parse a decklist from different locations.
99
1010
Args:

mtgproxies/decklists/decklist.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class Card:
2121
count: int
2222
card: dict[str | Any]
2323

24-
def __getitem__(self, key: str):
24+
def __getitem__(self, key: str) -> Any:
2525
return self.card[key]
2626

27-
def __contains__(self, key: str):
27+
def __contains__(self, key: str) -> bool:
2828
return key in self.card
2929

3030
@property
@@ -63,7 +63,7 @@ class Decklist:
6363
entries: list[Card | Comment] = field(default_factory=list)
6464
name: str = None
6565

66-
def append_card(self, count, card) -> None:
66+
def append_card(self, count: int, card) -> None:
6767
"""Append a card line to this decklist."""
6868
self.entries.append(Card(count, card))
6969

mtgproxies/decklists/sanitizing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def validate_card_name(card_name: str):
5656
return validated_name, warnings
5757

5858

59-
def get_print_warnings(card):
59+
def get_print_warnings(card) -> list[str]:
6060
"""Returns warnings for low-resolution scans."""
6161
warnings = []
6262
if not card["highres_image"] or card["digital"]:

mtgproxies/plotting/splitpages.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from __future__ import annotations
2+
3+
from types import TracebackType
4+
15
import matplotlib.pyplot as plt
26

37

@@ -7,15 +11,21 @@ class SplitPages:
711
This mirrors the functionality of the `PdfPages` wrapper from matplotlib.
812
"""
913

10-
def __init__(self, filename):
14+
def __init__(self, filename: str) -> None:
15+
"""Create a new SplitPages object."""
1116
self.file_basename = filename[: filename.rindex(".")]
1217
self.file_extension = filename[filename.rindex(".") :]
1318
self.pagecount = 0
1419

15-
def __enter__(self):
20+
def __enter__(self) -> SplitPages:
1621
return self
1722

18-
def __exit__(self, exc_type, exc_val, exc_tb):
23+
def __exit__(
24+
self,
25+
exc_type: type[BaseException] | None,
26+
exc_val: BaseException | None,
27+
exc_tb: TracebackType | None,
28+
):
1929
pass
2030

2131
def savefig(self, figure=None, **kwargs):

mtgproxies/print_cards.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def print_cards_fpdf(
104104
border_crop: int = 14,
105105
background_color: tuple[int, int, int] = None,
106106
cropmarks: bool = True,
107-
):
107+
) -> None:
108108
"""Print a list of cards to a pdf file.
109109
110110
Args:

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[tool.black]
22
line-length = 120
3+
target-version = ['py39', 'py310', 'py311', 'py312']

scryfall/rate_limit.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from __future__ import annotations
2+
13
import threading
24
import time
5+
from types import TracebackType
36

47

58
class RateLimiter:
@@ -23,5 +26,10 @@ def __enter__(self) -> None:
2326
self.last_call = time.time()
2427
return self
2528

26-
def __exit__(self, type, value, traceback) -> None:
29+
def __exit__(
30+
self,
31+
exc_type: type[BaseException] | None,
32+
exc_val: BaseException | None,
33+
exc_tb: TracebackType | None,
34+
) -> None:
2735
pass # Nothing to do here

setup.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[flake8]
2-
ignore = E203,E741,W503,D100,D104,D105,PL123,ANN101
2+
ignore = E203,E741,W503,D100,D104,D105,PL123,ANN101,ANN102
33
per-file-ignores =
4-
tests/*:D103,ANN201
4+
tests/*:D103,ANN201,ABS101
55
max-line-length = 120
66
docstring-convention = google
7-
known-modules = mtg-proxies:[mtgproxies,scryfall]
7+
known-modules = mtg-proxies:[mtgproxies,scryfall],fpdf2:[fpdf]
88

99
[isort]
1010
line_length = 120

setup.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
Modified by Madoshakalaka@Github (dependency links added)
77
"""
88

9-
from os import path
9+
from pathlib import Path
1010

1111
from setuptools import find_packages, setup
1212

13-
here = path.abspath(path.dirname(__file__))
13+
here = Path(__file__).parent
14+
1415

1516
# Get the long description from the README file
16-
with open(path.join(here, "README.md"), encoding="utf-8") as f:
17+
with open(here / "README.md", encoding="utf-8") as f:
1718
long_description = f.read()
1819

1920
# Arguments marked as "Required" below must be included for upload to PyPI.

test_token.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def find_token(type_line, power, toughness, colors, oracle_text):
2424
return scryfall.recommend_print(oracle_id=cards[0]["oracle_id"])
2525

2626

27-
def parse_colors(s):
27+
def parse_colors(s: str):
2828
colors = set()
2929

3030
reverse_color_names = {value: key for key, value in color_names.items()}

tests/decklist_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def test_parsing():
1919
@pytest.mark.parametrize(
2020
"archidekt_id,expected_first_card",
2121
[
22-
("1212142", "Squirrel Nest"),
23-
("42", "Merieke Ri Berit"),
22+
("1212142", "Emerald Medallion"),
23+
("42", "Dromar's Cavern"),
2424
],
2525
)
2626
def test_archidekt(archidekt_id: str, expected_first_card: str):

tests/scryfall_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_get_faces(id: str, n_faces: int):
1616
card = scryfall.card_by_id()[id]
1717
faces = scryfall.get_faces(card)
1818

19-
assert type(faces) == list
19+
assert type(faces) is list
2020
assert len(faces) == n_faces
2121
for face in faces:
2222
assert "illustration_id" in face

0 commit comments

Comments
 (0)