Skip to content

Commit 7cb996d

Browse files
committed
Upgrade Python syntax with pyupgrade
1 parent dc4831b commit 7cb996d

File tree

6 files changed

+24
-27
lines changed

6 files changed

+24
-27
lines changed

qrcode/console_scripts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import optparse
1010
import os
1111
import sys
12-
from typing import Dict, Iterable, NoReturn, Optional, Set, Type
12+
from typing import NoReturn, Optional
13+
from collections.abc import Iterable
1314
from importlib import metadata
1415

1516
import qrcode
@@ -140,7 +141,7 @@ def raise_error(msg: str) -> NoReturn:
140141
img.save(sys.stdout.buffer)
141142

142143

143-
def get_factory(module: str) -> Type[BaseImage]:
144+
def get_factory(module: str) -> type[BaseImage]:
144145
if "." not in module:
145146
raise ValueError("The image factory is not a full python path")
146147
module, name = module.rsplit(".", 1)
@@ -149,7 +150,7 @@ def get_factory(module: str) -> Type[BaseImage]:
149150

150151

151152
def get_drawer_help() -> str:
152-
help: Dict[str, Set] = {}
153+
help: dict[str, set] = {}
153154
for alias, module in default_factories.items():
154155
try:
155156
image = get_factory(module)

qrcode/image/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import abc
2-
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Type, Union
2+
from typing import TYPE_CHECKING, Any, Optional, Union
33

44
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
55

66
if TYPE_CHECKING:
77
from qrcode.main import ActiveWithNeighbors, QRCode
88

99

10-
DrawerAliases = Dict[str, Tuple[Type[QRModuleDrawer], Dict[str, Any]]]
10+
DrawerAliases = dict[str, tuple[type[QRModuleDrawer], dict[str, Any]]]
1111

1212

1313
class BaseImage:
@@ -16,7 +16,7 @@ class BaseImage:
1616
"""
1717

1818
kind: Optional[str] = None
19-
allowed_kinds: Optional[Tuple[str]] = None
19+
allowed_kinds: Optional[tuple[str]] = None
2020
needs_context = False
2121
needs_processing = False
2222
needs_drawrect = True
@@ -108,7 +108,7 @@ def is_eye(self, row: int, col: int):
108108

109109

110110
class BaseImageWithDrawer(BaseImage):
111-
default_drawer_class: Type[QRModuleDrawer]
111+
default_drawer_class: type[QRModuleDrawer]
112112
drawer_aliases: DrawerAliases = {}
113113

114114
def get_default_module_drawer(self) -> QRModuleDrawer:

qrcode/image/styles/moduledrawers/pil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, List
1+
from typing import TYPE_CHECKING
22

33
from PIL import Image, ImageDraw
44
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
@@ -136,7 +136,7 @@ def setup_corners(self):
136136
self.SE_ROUND = self.NW_ROUND.transpose(Image.Transpose.ROTATE_180)
137137
self.NE_ROUND = self.NW_ROUND.transpose(Image.Transpose.FLIP_LEFT_RIGHT)
138138

139-
def drawrect(self, box: List[List[int]], is_active: "ActiveWithNeighbors"):
139+
def drawrect(self, box: list[list[int]], is_active: "ActiveWithNeighbors"):
140140
if not is_active:
141141
return
142142
# find rounded edges

qrcode/image/svg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import decimal
22
from decimal import Decimal
3-
from typing import List, Optional, Type, Union, overload, Literal
3+
from typing import Optional, Union, overload, Literal
44

55
import qrcode.image.base
66
from qrcode.compat.etree import ET
@@ -18,7 +18,7 @@ class SvgFragmentImage(qrcode.image.base.BaseImageWithDrawer):
1818
_SVG_namespace = "http://www.w3.org/2000/svg"
1919
kind = "SVG"
2020
allowed_kinds = ("SVG",)
21-
default_drawer_class: Type[QRModuleDrawer] = svg_drawers.SvgSquareDrawer
21+
default_drawer_class: type[QRModuleDrawer] = svg_drawers.SvgSquareDrawer
2222

2323
def __init__(self, *args, **kwargs):
2424
ET.register_namespace("svg", self._SVG_namespace)
@@ -123,7 +123,7 @@ class SvgPathImage(SvgImage):
123123

124124
needs_processing = True
125125
path: Optional[ET.Element] = None
126-
default_drawer_class: Type[QRModuleDrawer] = svg_drawers.SvgPathSquareDrawer
126+
default_drawer_class: type[QRModuleDrawer] = svg_drawers.SvgPathSquareDrawer
127127
drawer_aliases = {
128128
"circle": (svg_drawers.SvgPathCircleDrawer, {}),
129129
"gapped-circle": (
@@ -137,7 +137,7 @@ class SvgPathImage(SvgImage):
137137
}
138138

139139
def __init__(self, *args, **kwargs):
140-
self._subpaths: List[str] = []
140+
self._subpaths: list[str] = []
141141
super().__init__(*args, **kwargs)
142142

143143
def _svg(self, viewBox=None, **kwargs):

qrcode/main.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import sys
22
from bisect import bisect_left
33
from typing import (
4-
Dict,
54
Generic,
6-
List,
75
NamedTuple,
86
Optional,
9-
Type,
107
TypeVar,
118
cast,
129
overload,
@@ -17,9 +14,9 @@
1714
from qrcode.image.base import BaseImage
1815
from qrcode.image.pure import PyPNGImage
1916

20-
ModulesType = List[List[Optional[bool]]]
17+
ModulesType = list[list[Optional[bool]]]
2118
# Cache modules generated just based on the QR Code version
22-
precomputed_qr_blanks: Dict[int, ModulesType] = {}
19+
precomputed_qr_blanks: dict[int, ModulesType] = {}
2320

2421

2522
def make(data=None, **kwargs):
@@ -84,7 +81,7 @@ def __init__(
8481
error_correction=constants.ERROR_CORRECT_M,
8582
box_size=10,
8683
border=4,
87-
image_factory: Optional[Type[GenericImage]] = None,
84+
image_factory: Optional[type[GenericImage]] = None,
8885
mask_pattern=None,
8986
):
9087
_check_box_size(box_size)
@@ -336,7 +333,7 @@ def make_image(
336333

337334
@overload
338335
def make_image(
339-
self, image_factory: Type[GenericImageLocal] = None, **kwargs
336+
self, image_factory: type[GenericImageLocal] = None, **kwargs
340337
) -> GenericImageLocal: ...
341338

342339
def make_image(self, image_factory=None, **kwargs):
@@ -527,13 +524,13 @@ def get_matrix(self):
527524
code = [[False] * width] * self.border
528525
x_border = [False] * self.border
529526
for module in self.modules:
530-
code.append(x_border + cast(List[bool], module) + x_border)
527+
code.append(x_border + cast(list[bool], module) + x_border)
531528
code += [[False] * width] * self.border
532529

533530
return code
534531

535532
def active_with_neighbors(self, row: int, col: int) -> ActiveWithNeighbors:
536-
context: List[bool] = []
533+
context: list[bool] = []
537534
for r in range(row - 1, row + 2):
538535
for c in range(col - 1, col + 2):
539536
context.append(self.is_constrained(r, c) and bool(self.modules[r][c]))

qrcode/util.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import math
22
import re
3-
from typing import List
43

54
from qrcode import LUT, base, exceptions
65
from qrcode.base import RSBlock
@@ -470,7 +469,7 @@ def __repr__(self):
470469

471470
class BitBuffer:
472471
def __init__(self):
473-
self.buffer: List[int] = []
472+
self.buffer: list[int] = []
474473
self.length = 0
475474

476475
def __repr__(self):
@@ -496,14 +495,14 @@ def put_bit(self, bit):
496495
self.length += 1
497496

498497

499-
def create_bytes(buffer: BitBuffer, rs_blocks: List[RSBlock]):
498+
def create_bytes(buffer: BitBuffer, rs_blocks: list[RSBlock]):
500499
offset = 0
501500

502501
maxDcCount = 0
503502
maxEcCount = 0
504503

505-
dcdata: List[List[int]] = []
506-
ecdata: List[List[int]] = []
504+
dcdata: list[list[int]] = []
505+
ecdata: list[list[int]] = []
507506

508507
for rs_block in rs_blocks:
509508
dcCount = rs_block.data_count

0 commit comments

Comments
 (0)