Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stubs/et_xmlfile/et_xmlfile/xmlfile.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import types
import xml.etree.ElementTree as ET
from _typeshed import Incomplete
from collections.abc import Generator
from contextlib import contextmanager
from contextlib import _GeneratorContextManager, contextmanager
from typing import Any

class LxmlSyntaxError(Exception): ...
Expand All @@ -27,7 +26,7 @@ class _IncrementalFileWriter:

class xmlfile:
encoding: str
writer_cm: Incomplete
writer_cm: _GeneratorContextManager[tuple[ET._FileWrite, str]] | None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we can actually type the first tuple element a bit more accurate by using:

Suggested change
writer_cm: _GeneratorContextManager[tuple[ET._FileWrite, str]] | None
writer_cm: _GeneratorContextManager[tuple[SupportsWrite[str], str]] | None

(SupportsWrite must be imported from _typeshed.) _FileWrite is a type alias, of which one element is SupportsWrite. But the other elements of this type alias don't make much sense if you look at how its used:

https://foss.heptapod.net/openpyxl/et_xmlfile/-/blob/branch/default/et_xmlfile/xmlfile.py?ref_type=heads#L91

This will actually just call the writer with a str.

def __init__(
self, output_file: ET._FileWrite, buffered: bool = False, encoding: str = "utf-8", close: bool = False
) -> None: ...
Expand Down