Skip to content

Add stubs for xlrd #13676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 25, 2025
2 changes: 2 additions & 0 deletions stubs/xlrd/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "2.0.*"
upstream_repository = "https://github.com/python-excel/xlrd"
41 changes: 41 additions & 0 deletions stubs/xlrd/xlrd/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
from _typeshed import SupportsWrite
from typing import Final

from . import timemachine as timemachine
from .biffh import (
XL_CELL_BLANK as XL_CELL_BLANK,
XL_CELL_BOOLEAN as XL_CELL_BOOLEAN,
XL_CELL_DATE as XL_CELL_DATE,
XL_CELL_EMPTY as XL_CELL_EMPTY,
XL_CELL_ERROR as XL_CELL_ERROR,
XL_CELL_NUMBER as XL_CELL_NUMBER,
XL_CELL_TEXT as XL_CELL_TEXT,
biff_text_from_num as biff_text_from_num,
error_text_from_code as error_text_from_code,
)
from .book import Book as Book, colname as colname, open_workbook_xls as open_workbook_xls
from .formula import *
from .info import __VERSION__ as __VERSION__, __version__ as __version__
from .sheet import empty_cell as empty_cell
from .xldate import XLDateError as XLDateError, xldate_as_datetime as xldate_as_datetime, xldate_as_tuple as xldate_as_tuple

FILE_FORMAT_DESCRIPTIONS: Final[dict[str, str]]
ZIP_SIGNATURE: Final[bytes]
PEEK_SIZE: Final[int]

def inspect_format(path: str | None = None, content: bytes | None = None) -> str | None: ...
def open_workbook(
filename: str | None = None,
logfile: SupportsWrite[str] = sys.stdout,
verbosity: int = 0,
use_mmap: bool = True,
file_contents: bytes | None = None,
encoding_override: str | None = None,
formatting_info: bool = False,
on_demand: bool = False,
ragged_rows: bool = False,
ignore_workbook_corruption: bool = False,
) -> Book: ...
def dump(filename: str, outfile: SupportsWrite[str] = sys.stdout, unnumbered: bool = False) -> None: ...
def count_records(filename: str, outfile: SupportsWrite[str] = sys.stdout) -> None: ...
176 changes: 176 additions & 0 deletions stubs/xlrd/xlrd/biffh.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import sys
from collections.abc import Callable
from typing import Any, Final, TextIO

from .timemachine import *

DEBUG: Final[int]

class XLRDError(Exception): ...

class BaseObject:
_repr_these: list[str]
def dump(self, f: TextIO | None = None, header: str | None = None, footer: str | None = None, indent: int = 0) -> None: ...

FUN: Final[int]
FDT: Final[int]
FNU: Final[int]
FGE: Final[int]
FTX: Final[int]
DATEFORMAT: Final[int]
NUMBERFORMAT: Final[int]
XL_CELL_EMPTY: Final[int]
XL_CELL_TEXT: Final[int]
XL_CELL_NUMBER: Final[int]
XL_CELL_DATE: Final[int]
XL_CELL_BOOLEAN: Final[int]
XL_CELL_ERROR: Final[int]
XL_CELL_BLANK: Final[int]
biff_text_from_num: Final[dict[int, str]]
error_text_from_code: Final[dict[int, str]]
BIFF_FIRST_UNICODE: Final[int]
XL_WORKBOOK_GLOBALS: Final[int]
WBKBLOBAL: Final[int]
XL_WORKBOOK_GLOBALS_4W: Final[int]
XL_WORKSHEET: Final[int]
WRKSHEET: Final[int]
XL_BOUNDSHEET_WORKSHEET: Final[int]
XL_BOUNDSHEET_CHART: Final[int]
XL_BOUNDSHEET_VB_MODULE: Final[int]
XL_ARRAY: Final[int]
XL_ARRAY2: Final[int]
XL_BLANK: Final[int]
XL_BLANK_B2: Final[int]
XL_BOF: Final[int]
XL_BOOLERR: Final[int]
XL_BOOLERR_B2: Final[int]
XL_BOUNDSHEET: Final[int]
XL_BUILTINFMTCOUNT: Final[int]
XL_CF: Final[int]
XL_CODEPAGE: Final[int]
XL_COLINFO: Final[int]
XL_COLUMNDEFAULT: Final[int]
XL_COLWIDTH: Final[int]
XL_CONDFMT: Final[int]
XL_CONTINUE: Final[int]
XL_COUNTRY: Final[int]
XL_DATEMODE: Final[int]
XL_DEFAULTROWHEIGHT: Final[int]
XL_DEFCOLWIDTH: Final[int]
XL_DIMENSION: Final[int]
XL_DIMENSION2: Final[int]
XL_EFONT: Final[int]
XL_EOF: Final[int]
XL_EXTERNNAME: Final[int]
XL_EXTERNSHEET: Final[int]
XL_EXTSST: Final[int]
XL_FEAT11: Final[int]
XL_FILEPASS: Final[int]
XL_FONT: Final[int]
XL_FONT_B3B4: Final[int]
XL_FORMAT: Final[int]
XL_FORMAT2: Final[int]
XL_FORMULA: Final[int]
XL_FORMULA3: Final[int]
XL_FORMULA4: Final[int]
XL_GCW: Final[int]
XL_HLINK: Final[int]
XL_QUICKTIP: Final[int]
XL_HORIZONTALPAGEBREAKS: Final[int]
XL_INDEX: Final[int]
XL_INTEGER: Final[int]
XL_IXFE: Final[int]
XL_LABEL: Final[int]
XL_LABEL_B2: Final[int]
XL_LABELRANGES: Final[int]
XL_LABELSST: Final[int]
XL_LEFTMARGIN: Final[int]
XL_TOPMARGIN: Final[int]
XL_RIGHTMARGIN: Final[int]
XL_BOTTOMMARGIN: Final[int]
XL_HEADER: Final[int]
XL_FOOTER: Final[int]
XL_HCENTER: Final[int]
XL_VCENTER: Final[int]
XL_MERGEDCELLS: Final[int]
XL_MSO_DRAWING: Final[int]
XL_MSO_DRAWING_GROUP: Final[int]
XL_MSO_DRAWING_SELECTION: Final[int]
XL_MULRK: Final[int]
XL_MULBLANK: Final[int]
XL_NAME: Final[int]
XL_NOTE: Final[int]
XL_NUMBER: Final[int]
XL_NUMBER_B2: Final[int]
XL_OBJ: Final[int]
XL_PAGESETUP: Final[int]
XL_PALETTE: Final[int]
XL_PANE: Final[int]
XL_PRINTGRIDLINES: Final[int]
XL_PRINTHEADERS: Final[int]
XL_RK: Final[int]
XL_ROW: Final[int]
XL_ROW_B2: Final[int]
XL_RSTRING: Final[int]
XL_SCL: Final[int]
XL_SHEETHDR: Final[int]
XL_SHEETPR: Final[int]
XL_SHEETSOFFSET: Final[int]
XL_SHRFMLA: Final[int]
XL_SST: Final[int]
XL_STANDARDWIDTH: Final[int]
XL_STRING: Final[int]
XL_STRING_B2: Final[int]
XL_STYLE: Final[int]
XL_SUPBOOK: Final[int]
XL_TABLEOP: Final[int]
XL_TABLEOP2: Final[int]
XL_TABLEOP_B2: Final[int]
XL_TXO: Final[int]
XL_UNCALCED: Final[int]
XL_UNKNOWN: Final[int]
XL_VERTICALPAGEBREAKS: Final[int]
XL_WINDOW2: Final[int]
XL_WINDOW2_B2: Final[int]
XL_WRITEACCESS: Final[int]
XL_WSBOOL: Final[int]
XL_XF: Final[int]
XL_XF2: Final[int]
XL_XF3: Final[int]
XL_XF4: Final[int]
boflen: Final[dict[int, int]]
bofcodes: Final[tuple[int, int, int, int]]
XL_FORMULA_OPCODES: Final[tuple[int, int, int]]

def is_cell_opcode(c: int) -> bool: ...
def upkbits(
tgt_obj: object, src: int, manifest: list[tuple[int, int, str]], local_setattr: Callable[[Any, str, Any], None] = ...
) -> None: ...
def upkbitsL(
tgt_obj: object,
src: int,
manifest: list[tuple[int, int, str]],
local_setattr: Callable[[Any, str, Any], None] = ...,
local_int: Callable[[Any], int] = ...,
) -> None: ...
def unpack_string(data: bytes, pos: int, encoding: str, lenlen: int = 1) -> str: ...
def unpack_string_update_pos(
data: bytes, pos: int, encoding: str, lenlen: int = 1, known_len: int | None = None
) -> tuple[str, int]: ...
def unpack_unicode(data: bytes, pos: int, lenlen: int = 2) -> str: ...
def unpack_unicode_update_pos(data: bytes, pos: int, lenlen: int = 2, known_len: int | None = None) -> tuple[str, int]: ...
def unpack_cell_range_address_list_update_pos(
output_list: list[tuple[int, int, int, int]], data: bytes, pos: int, biff_version: int, addr_size: int = 6
) -> int: ...

biff_rec_name_dict: Final[dict[int, str]]

def hex_char_dump(
strg: bytes, ofs: int, dlen: int, base: int = 0, fout: TextIO = sys.stdout, unnumbered: bool = False
) -> None: ...
def biff_dump(
mem: bytes, stream_offset: int, stream_len: int, base: int = 0, fout: TextIO = sys.stdout, unnumbered: bool = False
) -> None: ...
def biff_count_records(mem: bytes, stream_offset: int, stream_len: int, fout: TextIO = sys.stdout) -> None: ...

encoding_from_codepage: Final[dict[int, str]]
151 changes: 151 additions & 0 deletions stubs/xlrd/xlrd/book.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import sys
from _typeshed import SupportsWrite
from collections.abc import Iterator
from types import TracebackType
from typing import Final, Literal
from typing_extensions import Self

from .biffh import *
from .formatting import XF, Font, Format
from .formula import *
from .sheet import Cell, Sheet
from .timemachine import *

empty_cell: Final[Cell]
MY_EOF: Final[int]
SUPBOOK_UNK: Final[int]
SUPBOOK_INTERNAL: Final[int]
SUPBOOK_EXTERNAL: Final[int]
SUPBOOK_ADDIN: Final[int]
SUPBOOK_DDEOLE: Final[int]
SUPPORTED_VERSIONS: Final[tuple[int, ...]]
builtin_name_from_code: Final[dict[str, str]]
code_from_builtin_name: Final[dict[str, str]]

def open_workbook_xls(
filename: str | None = None,
logfile: SupportsWrite[str] = sys.stdout,
verbosity: int = 0,
use_mmap: bool = True,
file_contents: bytes | None = None,
encoding_override: str | None = None,
formatting_info: bool = False,
on_demand: bool = False,
ragged_rows: bool = False,
ignore_workbook_corruption: bool = False,
) -> Book: ...

class Name(BaseObject):
_repr_these: list[str]
book: Book | None = None
hidden: Literal[0, 1]
func: Literal[0, 1]
vbasic: Literal[0, 1]
macro: Literal[0, 1]
complex: Literal[0, 1]
builtin: Literal[0, 1]
funcgroup: Literal[0, 1]
binary: Literal[0, 1]
name_index: int
name: str
raw_formula: bytes
scope: Literal[-1, -2, -3, 0]
result: Operand | None
def cell(self) -> Cell: ...
def area2d(self, clipped: bool = True) -> tuple[Sheet, int, int, int, int]: ...

class Book(BaseObject):
nsheets: int
datemode: Literal[0, 1]
biff_version: int
name_obj_list: list[Name]
codepage: int | None
encoding: str | None
countries: tuple[int, int]
user_name: str
font_list: list[Font]
xf_list: list[XF]
format_list: list[Format]
format_map: dict[int, Format]
style_name_map: dict[str, tuple[int, int]]
colour_map: dict[int, tuple[int, int, int] | None]
palette_record: list[tuple[int, int, int]]
load_time_stage_1: float
load_time_stage_2: float
def sheets(self) -> list[Sheet]: ...
def sheet_by_index(self, sheetx: int) -> Sheet: ...
def __iter__(self) -> Iterator[Sheet]: ...
def sheet_by_name(self, sheet_name: str) -> Sheet: ...
def __getitem__(self, item: int | str) -> Sheet: ...
def sheet_names(self) -> list[str]: ...
def sheet_loaded(self, sheet_name_or_index: int | str) -> bool: ...
def unload_sheet(self, sheet_name_or_index: int | str) -> None: ...
mem: bytes | None = None
filestr: bytes | None = None
def release_resources(self) -> None: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
name_and_scope_map: dict[tuple[str, int], Name]
name_map: dict[str, list[Name]]
raw_user_name: bool
builtinfmtcount: int
addin_func_names: list[str]
def __init__(self) -> None: ...
logfile: SupportsWrite[str]
verbosity: int
use_mmap: bool
encoding_override: str | None
formatting_info: bool
on_demand: bool
ragged_rows: bool
stream_len: int
base: int
def biff2_8_load(
self,
filename: str | None = None,
file_contents: bytes | None = None,
logfile: SupportsWrite[str] = sys.stdout,
verbosity: int = 0,
use_mmap: bool = True,
encoding_override: str | None = None,
formatting_info: bool = False,
on_demand: bool = False,
ragged_rows: bool = False,
ignore_workbook_corruption: bool = False,
) -> None: ...
xfcount: int
actualfmtcount: int
def initialise_format_info(self) -> None: ...
def get2bytes(self) -> int: ...
def get_record_parts(self) -> tuple[int, int, bytes]: ...
def get_record_parts_conditional(self, reqd_record: int) -> tuple[int | None, int, bytes]: ...
def get_sheet(self, sh_number: int, update_pos: bool = True) -> Sheet: ...
def get_sheets(self) -> None: ...
def fake_globals_get_sheet(self) -> None: ...
def handle_boundsheet(self, data: bytes) -> None: ...
def handle_builtinfmtcount(self, data: bytes) -> None: ...
def derive_encoding(self) -> str: ...
def handle_codepage(self, data: bytes) -> None: ...
def handle_country(self, data: bytes) -> None: ...
def handle_datemode(self, data: bytes) -> None: ...
def handle_externname(self, data: bytes) -> None: ...
def handle_externsheet(self, data: bytes) -> None: ...
def handle_filepass(self, data: bytes) -> None: ...
def handle_name(self, data: bytes) -> None: ...
def names_epilogue(self) -> None: ...
def handle_obj(self, data: bytes) -> None: ...
def handle_supbook(self, data: bytes) -> None: ...
def handle_sheethdr(self, data: bytes) -> None: ...
def handle_sheetsoffset(self, data: bytes) -> None: ...
def handle_sst(self, data: bytes) -> None: ...
def handle_writeaccess(self, data: bytes) -> None: ...
def parse_globals(self) -> None: ...
def read(self, pos: int, length: int) -> bytes: ...
def getbof(self, rqd_stream: int) -> int | None: ...

# Helper functions
def expand_cell_address(inrow: int, incol: int) -> tuple[int, int, int, int]: ...
def display_cell_address(rowx: int, colx: int, relrow: int, relcol: int) -> str: ...
def unpack_SST_table(datatab: list[bytes], nstrings: int) -> tuple[list[str], dict[int, list[tuple[int, int]]]]: ...
Loading