Skip to content

Conversation

@9en9i
Copy link

@9en9i 9en9i commented Dec 17, 2025

@9en9i 9en9i changed the title Enhance ExcelWriter with generic type support and overloads TYP: enhance ExcelWriter with generic type support and overloads Dec 17, 2025
@overload
def __init__(
self,
self: ExcelWriter,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think

Suggested change
self: ExcelWriter,
self,

will do

def __init__(
self,
self: ExcelWriter,
path: FilePath | WriteExcelBuffer | ExcelWriter,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs only FilePath and BinaryIO are supported

Suggested change
path: FilePath | WriteExcelBuffer | ExcelWriter,
path: FilePath | BinaryIO,

Also to other overloads

Comment on lines +229 to +235
engine: Literal["auto"] | None = ...,
date_format: str | None = ...,
datetime_format: str | None = ...,
mode: Literal["w", "a"] = ...,
storage_options: StorageOptions = ...,
if_sheet_exists: ExcelWriterIfSheetExists | None = ...,
engine_kwargs: dict[str, Any] | None = ...,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default values

Suggested change
engine: Literal["auto"] | None = ...,
date_format: str | None = ...,
datetime_format: str | None = ...,
mode: Literal["w", "a"] = ...,
storage_options: StorageOptions = ...,
if_sheet_exists: ExcelWriterIfSheetExists | None = ...,
engine_kwargs: dict[str, Any] | None = ...,
engine: Literal["auto"] | None = None,
date_format: str | None = None,
datetime_format: str | None = None,
mode: Literal["w", "a"] = "w",
storage_options: StorageOptions = None,
if_sheet_exists: ExcelWriterIfSheetExists = "error",
engine_kwargs: Mapping[str, Any] | None = None,

Also to other overloads

def __init__(
self: ExcelWriter[Workbook],
path: FilePath | WriteExcelBuffer | ExcelWriter[Workbook],
engine: Literal["openpyxl"] = ...,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
engine: Literal["openpyxl"] = ...,
engine: Literal["openpyxl"],

it has to be the fixed literal openpyxl, if I'm not mistaken

def __init__(
self: ExcelWriter[OpenDocument],
path: FilePath | WriteExcelBuffer | ExcelWriter[OpenDocument],
engine: Literal["odf"] = ...,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
engine: Literal["odf"] = ...,
engine: Literal["odf"],

def __init__(
self: ExcelWriter[XlsxWorkbook],
path: FilePath | WriteExcelBuffer | ExcelWriter[XlsxWorkbook],
engine: Literal["xlsxwriter"] = ...,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
engine: Literal["xlsxwriter"] = ...,
engine: Literal["xlsxwriter"],


class ExcelWriter(Generic[_WorkbookT]):
@overload
def __init__(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused, maybe we should overload __new__ instead of __init__ here? cc @Dr-Irv @loicdiridollou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants