Skip to content

Accept file objects in MODE_AUTO and check the database argument - #471

Open
oschwald wants to merge 5 commits into
greg/stf-1960from
greg/stf-1961
Open

oschwald wants to merge 5 commits into
greg/stf-1960from
greg/stf-1961

Conversation

@oschwald

@oschwald oschwald commented Oct 3, 2026

Copy link
Copy Markdown
Member

Lets MODE_AUTO read a file object and gives clear errors for a database argument that does not suit the mode. Stacked on #470; review only the commits in this PR.

  • File objects in MODE_AUTO. With the extension installed, MODE_AUTO passed every argument to the extension, which accepts only a path, so a file object raised TypeError. MODE_AUTO now reads a file object into memory with the pure Python reader, as MODE_FD does. A path object that also has a text read(), such as py.path.local, still opens as a path. A file descriptor still raises TypeError with the extension, as before.
  • Argument checks. The pure Python reader now raises TypeError with the fix for a path with MODE_FD, a file object with a path mode, a text-mode file, a read() that does not return bytes, and a bool. Before, some of these raised AttributeError or an unrelated error. A descriptor object with __index__, such as numpy.int64, still works in the path modes.
  • Docs. The docstrings and README described MODE_FD as taking a file descriptor. They now say it takes a binary file object, and they note that a file object in MODE_AUTO uses the slower pure Python reader.

STF-1961

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 3, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 490078d3-9e1d-4ffd-94bd-10a4d113c476

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 16:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 3, 2026 17:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

oschwald and others added 5 commits October 3, 2026 17:33
MODE_AUTO passed every database argument to the C extension when it was
installed, but the extension accepts only a path. A file object raised
TypeError, although the pure Python reader can read it. Without the
extension, a file object also raised TypeError.

In MODE_AUTO, read a file object as MODE_FD does. A path still opens as
a path, even if it also has read(), because some path objects, such as
py.path.local, have a text read(). A file descriptor still raises
TypeError with the extension, as before. The pure Python path modes
close a descriptor, and a caller of the default mode might not expect
that. Without the extension, MODE_AUTO still opens a descriptor, as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MODE_FD calls database.read(), so it takes a binary file object, and
MODE_AUTO now reads one the same way. The docstrings and the README said
that MODE_FD takes a file descriptor. An int file descriptor fails with
AttributeError in MODE_FD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_load_buffer passed the database argument to open(), FileBuffer and
.read() behind 5 type: ignore comments, and it declared -> str although
it returns the database argument or a file object name. An Any local
hid that mismatch. The ignores hid real mismatches too. MODE_FD with a
path raised AttributeError, and a path mode with a file object raised a
TypeError from open() that did not name the mode.

Check the argument type for the mode and raise TypeError with the fix.
The checks narrow the type, so the ignores go away. FileBuffer now takes
the path types that open() accepts. The unsupported mode check still
comes first. The function returns object, because the caller only
formats the name into error messages.

A text file is refused before read(), which could fail to decode it. A
bytearray from read() stays a bytearray, as before, so the buffer and
decoder types now include it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pure Python Reader accepts MODE_MMAP, but the error for an
unsupported mode listed only MODE_AUTO, MODE_FILE, MODE_MEMORY and
MODE_FD. A caller who passed MODE_MMAP_EXT was told that MODE_MMAP
was not supported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The name for a file object without a name attribute was
f"<{type(database)}>", so error messages showed
"<<class '_io.BytesIO'>>". MODE_AUTO now reads file objects too, so
these messages are more common. Use the type name, as in "<BytesIO>".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 3, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants