Add stubs for qrcode (#10380)

This commit is contained in:
Sebastian Rittau
2023-07-20 14:36:20 +02:00
committed by GitHub
parent 4f56889f23
commit a04cb3b058
24 changed files with 551 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
# Internal modules
qrcode\.compat
qrcode\.compat\..*
qrcode\.tests
qrcode\.tests\..*
# Stubtest hiccup: It doesn't recognize that the annotated type is a base
# class of the default class assigned to the attribute.
qrcode\.image\..*\.default_drawer_class
# Leaked loop counter
qrcode.base.i

View File

@@ -0,0 +1,4 @@
version = "7.4.*"
[tool.stubtest]
extras = ["lxml"]

View File

@@ -0,0 +1,3 @@
from _typeshed import Incomplete
rsPoly_LUT: Incomplete

View File

@@ -0,0 +1,10 @@
from qrcode import image as image
from qrcode.constants import (
ERROR_CORRECT_H as ERROR_CORRECT_H,
ERROR_CORRECT_L as ERROR_CORRECT_L,
ERROR_CORRECT_M as ERROR_CORRECT_M,
ERROR_CORRECT_Q as ERROR_CORRECT_Q,
)
from qrcode.main import make as make
def run_example(data: str = "http://www.lincolnloop.com", *args, **kwargs) -> None: ...

View File

@@ -0,0 +1,25 @@
from _typeshed import Incomplete
from typing import NamedTuple
EXP_TABLE: Incomplete
LOG_TABLE: Incomplete
RS_BLOCK_OFFSET: Incomplete
RS_BLOCK_TABLE: Incomplete
def glog(n): ...
def gexp(n): ...
class Polynomial:
num: Incomplete
def __init__(self, num, shift) -> None: ...
def __getitem__(self, index): ...
def __iter__(self): ...
def __len__(self) -> int: ...
def __mul__(self, other): ...
def __mod__(self, other): ...
class RSBlock(NamedTuple):
total_count: int
data_count: int
def rs_blocks(version, error_correction): ...

View File

@@ -0,0 +1,12 @@
from _typeshed import Incomplete
from collections.abc import Iterable
from qrcode.image.base import BaseImage, DrawerAliases as DrawerAliases
default_factories: Incomplete
error_correction: Incomplete
def main(args: Incomplete | None = None) -> None: ...
def get_factory(module: str) -> type[BaseImage]: ...
def get_drawer_help() -> str: ...
def commas(items: Iterable[str], joiner: str = "or") -> str: ...

View File

@@ -0,0 +1,4 @@
ERROR_CORRECT_L: int
ERROR_CORRECT_M: int
ERROR_CORRECT_Q: int
ERROR_CORRECT_H: int

View File

@@ -0,0 +1 @@
class DataOverflowError(Exception): ...

View File

View File

@@ -0,0 +1,50 @@
import abc
from _typeshed import Incomplete
from typing import Any
from typing_extensions import TypeAlias
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
from qrcode.main import QRCode
DrawerAliases: TypeAlias = dict[str, tuple[type[QRModuleDrawer], dict[str, Any]]]
class BaseImage(metaclass=abc.ABCMeta):
kind: str | None
allowed_kinds: tuple[str] | None
needs_context: bool
needs_processing: bool
needs_drawrect: bool
border: Incomplete
width: Incomplete
box_size: Incomplete
pixel_size: Incomplete
modules: Incomplete
def __init__(self, border, width, box_size, *args, **kwargs) -> None: ...
@abc.abstractmethod
def drawrect(self, row, col): ...
def drawrect_context(self, row: int, col: int, qr: QRCode[Incomplete]): ...
def process(self) -> None: ...
@abc.abstractmethod
def save(self, stream, kind: Incomplete | None = None): ...
def pixel_box(self, row, col): ...
@abc.abstractmethod
def new_image(self, **kwargs) -> Any: ...
def init_new_image(self) -> None: ...
def get_image(self, **kwargs): ...
def check_kind(self, kind, transform: Incomplete | None = None): ...
def is_eye(self, row: int, col: int): ...
class BaseImageWithDrawer(BaseImage, metaclass=abc.ABCMeta):
default_drawer_class: type[QRModuleDrawer]
drawer_aliases: DrawerAliases
def get_default_module_drawer(self) -> QRModuleDrawer: ...
def get_default_eye_drawer(self) -> QRModuleDrawer: ...
needs_context: bool
module_drawer: QRModuleDrawer
eye_drawer: QRModuleDrawer
def __init__(
self, *args, module_drawer: QRModuleDrawer | str | None = None, eye_drawer: QRModuleDrawer | str | None = None, **kwargs
) -> None: ...
def get_drawer(self, drawer: QRModuleDrawer | str | None) -> QRModuleDrawer | None: ...
def init_new_image(self): ...
def drawrect_context(self, row: int, col: int, qr: QRCode[Incomplete]): ...

View File

@@ -0,0 +1,11 @@
from _typeshed import Incomplete
import qrcode.image.base
class PilImage(qrcode.image.base.BaseImage):
kind: str
fill_color: Incomplete
def new_image(self, **kwargs): ...
def drawrect(self, row, col) -> None: ...
def save(self, stream, format: Incomplete | None = None, **kwargs) -> None: ... # type: ignore[override]
def __getattr__(self, name): ...

View File

@@ -0,0 +1,16 @@
from _typeshed import Incomplete
from collections.abc import Generator
import qrcode.image.base
class PyPNGImage(qrcode.image.base.BaseImage):
kind: str
allowed_kinds: Incomplete
needs_drawrect: bool
def new_image(self, **kwargs): ...
def drawrect(self, row, col) -> None: ...
def save(self, stream, kind: Incomplete | None = None) -> None: ...
def rows_iter(self) -> Generator[Incomplete, Incomplete, None]: ...
def border_rows_iter(self) -> Generator[Incomplete, None, None]: ...
PymagingImage = PyPNGImage

View File

@@ -0,0 +1,22 @@
import abc
from _typeshed import Incomplete
import qrcode.image.base
from qrcode.image.styles.colormasks import QRColorMask
from qrcode.image.styles.moduledrawers import SquareModuleDrawer
class StyledPilImage(qrcode.image.base.BaseImageWithDrawer, metaclass=abc.ABCMeta):
kind: str
needs_processing: bool
color_mask: QRColorMask
default_drawer_class = SquareModuleDrawer
embeded_image: Incomplete
embeded_image_resample: Incomplete
paint_color: Incomplete
def __init__(self, *args, **kwargs) -> None: ...
def new_image(self, **kwargs): ...
def init_new_image(self) -> None: ...
def process(self) -> None: ...
def draw_embeded_image(self) -> None: ...
def save(self, stream, format: Incomplete | None = None, **kwargs) -> None: ... # type: ignore[override]
def __getattr__(self, name): ...

View File

@@ -0,0 +1,65 @@
from _typeshed import Incomplete
class QRColorMask:
back_color: Incomplete
has_transparency: bool
paint_color = back_color
def initialize(self, styledPilImage, image) -> None: ...
def apply_mask(self, image) -> None: ...
def get_fg_pixel(self, image, x, y) -> None: ...
def get_bg_pixel(self, image, x, y): ...
def interp_num(self, n1, n2, norm): ...
def interp_color(self, col1, col2, norm): ...
def extrap_num(self, n1, n2, interped_num): ...
def extrap_color(self, col1, col2, interped_color): ...
class SolidFillColorMask(QRColorMask):
back_color: Incomplete
front_color: Incomplete
has_transparency: Incomplete
def __init__(self, back_color=(255, 255, 255), front_color=(0, 0, 0)) -> None: ...
def apply_mask(self, image) -> None: ...
def get_fg_pixel(self, image, x, y): ...
class RadialGradiantColorMask(QRColorMask):
back_color: Incomplete
center_color: Incomplete
edge_color: Incomplete
has_transparency: Incomplete
def __init__(self, back_color=(255, 255, 255), center_color=(0, 0, 0), edge_color=(0, 0, 255)) -> None: ...
def get_fg_pixel(self, image, x, y): ...
class SquareGradiantColorMask(QRColorMask):
back_color: Incomplete
center_color: Incomplete
edge_color: Incomplete
has_transparency: Incomplete
def __init__(self, back_color=(255, 255, 255), center_color=(0, 0, 0), edge_color=(0, 0, 255)) -> None: ...
def get_fg_pixel(self, image, x, y): ...
class HorizontalGradiantColorMask(QRColorMask):
back_color: Incomplete
left_color: Incomplete
right_color: Incomplete
has_transparency: Incomplete
def __init__(self, back_color=(255, 255, 255), left_color=(0, 0, 0), right_color=(0, 0, 255)) -> None: ...
def get_fg_pixel(self, image, x, y): ...
class VerticalGradiantColorMask(QRColorMask):
back_color: Incomplete
top_color: Incomplete
bottom_color: Incomplete
has_transparency: Incomplete
def __init__(self, back_color=(255, 255, 255), top_color=(0, 0, 0), bottom_color=(0, 0, 255)) -> None: ...
def get_fg_pixel(self, image, x, y): ...
class ImageColorMask(QRColorMask):
back_color: Incomplete
color_img: Incomplete
has_transparency: Incomplete
def __init__(
self, back_color=(255, 255, 255), color_mask_path: Incomplete | None = None, color_mask_image: Incomplete | None = None
) -> None: ...
paint_color: Incomplete
def initialize(self, styledPilImage, image) -> None: ...
def get_fg_pixel(self, image, x, y): ...

View File

@@ -0,0 +1,8 @@
from .pil import (
CircleModuleDrawer as CircleModuleDrawer,
GappedSquareModuleDrawer as GappedSquareModuleDrawer,
HorizontalBarsDrawer as HorizontalBarsDrawer,
RoundedModuleDrawer as RoundedModuleDrawer,
SquareModuleDrawer as SquareModuleDrawer,
VerticalBarsDrawer as VerticalBarsDrawer,
)

View File

@@ -0,0 +1,12 @@
import abc
from _typeshed import Incomplete
from qrcode.image.base import BaseImage
class QRModuleDrawer(abc.ABC, metaclass=abc.ABCMeta):
needs_neighbors: bool
def __init__(self, **kwargs) -> None: ...
img: Incomplete
def initialize(self, img: BaseImage) -> None: ...
@abc.abstractmethod
def drawrect(self, box, is_active) -> None: ...

View File

@@ -0,0 +1,69 @@
import abc
from _typeshed import Incomplete
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
from qrcode.main import ActiveWithNeighbors
ANTIALIASING_FACTOR: int
class StyledPilQRModuleDrawer(QRModuleDrawer, metaclass=abc.ABCMeta):
img: StyledPilImage
class SquareModuleDrawer(StyledPilQRModuleDrawer):
imgDraw: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def drawrect(self, box, is_active: bool): ...
class GappedSquareModuleDrawer(StyledPilQRModuleDrawer):
size_ratio: Incomplete
def __init__(self, size_ratio: float = 0.8) -> None: ...
imgDraw: Incomplete
delta: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def drawrect(self, box, is_active: bool): ...
class CircleModuleDrawer(StyledPilQRModuleDrawer):
circle: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def drawrect(self, box, is_active: bool): ...
class RoundedModuleDrawer(StyledPilQRModuleDrawer):
needs_neighbors: bool
radius_ratio: Incomplete
def __init__(self, radius_ratio: int = 1) -> None: ...
corner_width: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
SQUARE: Incomplete
NW_ROUND: Incomplete
SW_ROUND: Incomplete
SE_ROUND: Incomplete
NE_ROUND: Incomplete
def setup_corners(self) -> None: ...
def drawrect(self, box: list[list[int]], is_active: ActiveWithNeighbors): ...
class VerticalBarsDrawer(StyledPilQRModuleDrawer):
needs_neighbors: bool
horizontal_shrink: Incomplete
def __init__(self, horizontal_shrink: float = 0.8) -> None: ...
half_height: Incomplete
delta: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
SQUARE: Incomplete
ROUND_TOP: Incomplete
ROUND_BOTTOM: Incomplete
def setup_edges(self) -> None: ...
def drawrect(self, box, is_active: ActiveWithNeighbors): ...
class HorizontalBarsDrawer(StyledPilQRModuleDrawer):
needs_neighbors: bool
vertical_shrink: Incomplete
def __init__(self, vertical_shrink: float = 0.8) -> None: ...
half_width: Incomplete
delta: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
SQUARE: Incomplete
ROUND_LEFT: Incomplete
ROUND_RIGHT: Incomplete
def setup_edges(self) -> None: ...
def drawrect(self, box, is_active: ActiveWithNeighbors): ...

View File

@@ -0,0 +1,59 @@
import abc
from _typeshed import Incomplete
from decimal import Decimal
from typing import NamedTuple
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
from qrcode.image.svg import SvgFragmentImage, SvgPathImage
ANTIALIASING_FACTOR: int
class Coords(NamedTuple):
x0: Decimal
y0: Decimal
x1: Decimal
y1: Decimal
xh: Decimal
yh: Decimal
class BaseSvgQRModuleDrawer(QRModuleDrawer, metaclass=abc.ABCMeta):
img: SvgFragmentImage
size_ratio: Incomplete
def __init__(self, *, size_ratio: Decimal = ..., **kwargs) -> None: ...
box_delta: Incomplete
box_size: Incomplete
box_half: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def coords(self, box) -> Coords: ...
class SvgQRModuleDrawer(BaseSvgQRModuleDrawer, metaclass=abc.ABCMeta):
tag: str
tag_qname: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def drawrect(self, box, is_active: bool): ...
@abc.abstractmethod
def el(self, box): ...
class SvgSquareDrawer(SvgQRModuleDrawer):
unit_size: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def el(self, box): ...
class SvgCircleDrawer(SvgQRModuleDrawer):
tag: str
radius: Incomplete
def initialize(self, *args, **kwargs) -> None: ...
def el(self, box): ...
class SvgPathQRModuleDrawer(BaseSvgQRModuleDrawer, metaclass=abc.ABCMeta):
img: SvgPathImage
def drawrect(self, box, is_active: bool): ...
@abc.abstractmethod
def subpath(self, box) -> str: ...
class SvgPathSquareDrawer(SvgPathQRModuleDrawer):
def subpath(self, box) -> str: ...
class SvgPathCircleDrawer(SvgPathQRModuleDrawer):
def initialize(self, *args, **kwargs) -> None: ...
def subpath(self, box) -> str: ...

View File

@@ -0,0 +1,42 @@
import abc
from _typeshed import Incomplete
from decimal import Decimal
from typing import overload
from typing_extensions import Literal
from xml.etree.ElementTree import Element
import qrcode.image.base
from qrcode.image.styles.moduledrawers.base import QRModuleDrawer
class SvgFragmentImage(qrcode.image.base.BaseImageWithDrawer, metaclass=abc.ABCMeta):
kind: str
allowed_kinds: Incomplete
default_drawer_class: type[QRModuleDrawer]
unit_size: Incomplete
def __init__(self, *args, **kwargs) -> None: ...
@overload
def units(self, pixels: int | Decimal, text: Literal[False]) -> Decimal: ...
@overload
def units(self, pixels: int | Decimal, text: Literal[True] = True) -> str: ...
def save(self, stream, kind: Incomplete | None = None) -> None: ...
def to_string(self, **kwargs): ...
def new_image(self, **kwargs): ...
class SvgImage(SvgFragmentImage, metaclass=abc.ABCMeta):
background: str | None
drawer_aliases: qrcode.image.base.DrawerAliases
class SvgPathImage(SvgImage, metaclass=abc.ABCMeta):
QR_PATH_STYLE: Incomplete
needs_processing: bool
path: Element | None
default_drawer_class: type[QRModuleDrawer]
drawer_aliases: Incomplete
def __init__(self, *args, **kwargs) -> None: ...
def process(self) -> None: ...
class SvgFillImage(SvgImage, metaclass=abc.ABCMeta):
background: str
class SvgPathFillImage(SvgPathImage, metaclass=abc.ABCMeta):
background: str

View File

@@ -0,0 +1,70 @@
from _typeshed import Incomplete
from typing import Generic, NamedTuple, TypeVar, overload
from typing_extensions import Literal, TypeAlias
from qrcode.image.base import BaseImage
ModulesType: TypeAlias = list[list[bool | None]]
precomputed_qr_blanks: dict[int, ModulesType]
def make(data: Incomplete | None = None, **kwargs): ...
def copy_2d_array(x): ...
class ActiveWithNeighbors(NamedTuple):
NW: bool
N: bool
NE: bool
W: bool
me: bool
E: bool
SW: bool
S: bool
SE: bool
def __bool__(self) -> bool: ...
GenericImage = TypeVar("GenericImage", bound=BaseImage) # noqa: Y001
GenericImageLocal = TypeVar("GenericImageLocal", bound=BaseImage) # noqa: Y001
class QRCode(Generic[GenericImage]):
modules: ModulesType
error_correction: Incomplete
box_size: Incomplete
border: Incomplete
image_factory: Incomplete
def __init__(
self,
version: Incomplete | None = None,
error_correction=0,
box_size: int = 10,
border: int = 4,
image_factory: type[GenericImage] | None = None,
mask_pattern: Incomplete | None = None,
) -> None: ...
@property
def version(self) -> int: ...
@property
def mask_pattern(self): ...
modules_count: int
data_cache: Incomplete
data_list: Incomplete
def clear(self) -> None: ...
def add_data(self, data, optimize: int = 20) -> None: ...
def make(self, fit: bool = True) -> None: ...
def makeImpl(self, test, mask_pattern) -> None: ...
def setup_position_probe_pattern(self, row, col) -> None: ...
def best_fit(self, start: Incomplete | None = None): ...
def best_mask_pattern(self): ...
def print_tty(self, out: Incomplete | None = None) -> None: ...
def print_ascii(self, out: Incomplete | None = None, tty: bool = False, invert: bool = False): ...
@overload
def make_image(self, image_factory: Literal[None] = None, **kwargs) -> GenericImage: ...
@overload
def make_image(self, image_factory: type[GenericImageLocal] | None = None, **kwargs) -> GenericImageLocal: ...
def is_constrained(self, row: int, col: int) -> bool: ...
def setup_timing_pattern(self) -> None: ...
def setup_position_adjust_pattern(self) -> None: ...
def setup_type_number(self, test) -> None: ...
def setup_type_info(self, test, mask_pattern) -> None: ...
def map_data(self, data, mask_pattern) -> None: ...
def get_matrix(self): ...
def active_with_neighbors(self, row: int, col: int) -> ActiveWithNeighbors: ...

View File

@@ -0,0 +1 @@
def update_manpage(data) -> None: ...

View File

@@ -0,0 +1,54 @@
from _typeshed import Incomplete
from collections.abc import Generator
from qrcode.base import RSBlock as RSBlock
MODE_NUMBER: Incomplete
MODE_ALPHA_NUM: Incomplete
MODE_8BIT_BYTE: Incomplete
MODE_KANJI: Incomplete
MODE_SIZE_SMALL: Incomplete
MODE_SIZE_MEDIUM: Incomplete
MODE_SIZE_LARGE: Incomplete
ALPHA_NUM: bytes
RE_ALPHA_NUM: Incomplete
NUMBER_LENGTH: Incomplete
PATTERN_POSITION_TABLE: Incomplete
G15: Incomplete
G18: Incomplete
G15_MASK: Incomplete
PAD0: int
PAD1: int
BIT_LIMIT_TABLE: Incomplete
def BCH_type_info(data): ...
def BCH_type_number(data): ...
def BCH_digit(data): ...
def pattern_position(version): ...
def mask_func(pattern): ...
def mode_sizes_for_version(version): ...
def length_in_bits(mode, version): ...
def check_version(version) -> None: ...
def lost_point(modules): ...
def optimal_data_chunks(data, minimum: int = 4) -> Generator[Incomplete, None, None]: ...
def to_bytestring(data): ...
def optimal_mode(data): ...
class QRData:
mode: Incomplete
data: Incomplete
def __init__(self, data, mode: Incomplete | None = None, check_data: bool = True) -> None: ...
def __len__(self) -> int: ...
def write(self, buffer) -> None: ...
class BitBuffer:
buffer: Incomplete
length: int
def __init__(self) -> None: ...
def get(self, index): ...
def put(self, num, length) -> None: ...
def __len__(self) -> int: ...
def put_bit(self, bit) -> None: ...
def create_bytes(buffer: BitBuffer, rs_blocks: list[RSBlock]): ...
def create_data(version, error_correction, data_list): ...