Skip to content
Merged
Show file tree
Hide file tree
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: 3 additions & 2 deletions src/java/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Readable,
Throwable,
)
from java.nio import CharBuffer
from java.nio.channels import FileChannel
from java.nio.charset import Charset, CharsetDecoder

Expand Down Expand Up @@ -334,8 +335,8 @@ def nullReader():
# type: () -> Reader
pass

def read(self, *args):
# type: (*Any) -> int
def read(self, cb):
# type: (CharBuffer) -> int
pass

def ready(self):
Expand Down
3 changes: 2 additions & 1 deletion stubs/stubs/java/io/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from java.lang import (
Readable,
Throwable,
)
from java.nio import CharBuffer
from java.nio.channels import FileChannel
from java.nio.charset import Charset, CharsetDecoder

Expand Down Expand Up @@ -112,7 +113,7 @@ class Reader(Object, Readable, Closeable):
def markSupported(self) -> bool: ...
@staticmethod
def nullReader() -> Reader: ...
def read(self, *args: Any) -> int: ...
def read(self, cb: CharBuffer) -> int: ...
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: The stub now models only a single read(CharBuffer) shape; consider overloads if other read variants are intended.

The old *args: Any signature was imprecise but did indicate multiple read variants. If this stub is meant to cover the full Java API (e.g., read(), read(char[], int, int)), representing each as an explicit @overload would be more accurate than a single read(self, cb: CharBuffer) -> int signature.

Suggested implementation:

    @staticmethod
    def nullReader() -> Reader: ...

    @overload
    def read(self) -> int: ...
    @overload
    def read(self, cb: CharBuffer) -> int: ...
    @overload
    def read(self, cbuf: list[str]) -> int: ...
    @overload
    def read(self, cbuf: list[str], off: int, length: int) -> int: ...

    def ready(self) -> bool: ...

`.

Here are the edits:

<file_operations>
<file_operation operation="edit" file_path="stubs/stubs/java/io/init.pyi">
<<<<<<< SEARCH
@staticmethod
def nullReader() -> Reader: ...
def read(self, cb: CharBuffer) -> int: ...
def ready(self) -> bool: ...

@staticmethod
def nullReader() -> Reader: ...

@overload
def read(self) -> int: ...
@overload
def read(self, cb: CharBuffer) -> int: ...
@overload
def read(self, cbuf: list[str]) -> int: ...
@overload
def read(self, cbuf: list[str], off: int, length: int) -> int: ...

def ready(self) -> bool: ...

REPLACE
</file_operation>
</file_operations>

<additional_changes>

  1. Ensure from typing import overload is present at the top of stubs/stubs/java/io/__init__.pyi. If the file already imports from typing, extend that import to include overload.
  2. If your codebase uses a different type to model Java char[] (e.g., Sequence[str] or a custom CharArray), adjust the cbuf: list[str] annotations accordingly to match your existing conventions.

def ready(self) -> bool: ...
def reset(self) -> None: ...
def skip(self, n: long) -> long: ...
Expand Down