Skip to content

fix: add AsyncResponse type to niquests response object#439

Open
kyteinsky wants to merge 1 commit into
mainfrom
fix/niquests-response-type
Open

fix: add AsyncResponse type to niquests response object#439
kyteinsky wants to merge 1 commit into
mainfrom
fix/niquests-response-type

Conversation

@kyteinsky
Copy link
Copy Markdown
Contributor

@kyteinsky kyteinsky commented Jun 2, 2026

Changes proposed in this pull request:

Summary by CodeRabbit

  • Refactor
    • Enhanced error handling to support both synchronous and asynchronous response objects, improving consistency across the library.

Signed-off-by: kyteinsky <kyteinsky@gmail.com>
@kyteinsky kyteinsky requested a review from oleksandr-nc June 2, 2026 14:14
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The exception module is updated to support both synchronous and asynchronous response objects. Import statements, the base exception class, three specialized exceptions, and the public error-checking function all expand their response type annotations from Response | None to AsyncResponse | Response | None.

Changes

Exception response type broadening

Layer / File(s) Summary
Base exception and import
nc_py_api/_exceptions.py
AsyncResponse is imported and the NextcloudException base class accepts AsyncResponse | Response | None for its response field and constructor parameter, enabling async response handling.
Derived exceptions and check_error utility
nc_py_api/_exceptions.py
NextcloudExceptionNotModified, NextcloudExceptionNotFound, and NextcloudMissingCapabilities constructors are updated to accept AsyncResponse | Response | None. The check_error() function parameter type is broadened to accept AsyncResponse | Response.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately reflects the main change: broadening type annotations in exception handling to support AsyncResponse alongside Response.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/niquests-response-type

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nc_py_api/_exceptions.py`:
- Line 3: The import may fail on older niquests releases because AsyncResponse
may not be re-exported; update the code to handle that by adding a fallback
import or pinning niquests: either pin niquests to a version known to export
AsyncResponse in your dependency manifest, or modify the import in
_exceptions.py to try the current top-level import of AsyncResponse, HTTPError,
Response and on ImportError fall back to the module path that actually defines
AsyncResponse (e.g., the internal async submodule) so the symbols AsyncResponse,
HTTPError, and Response are always available.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31cc61d6-8366-4c01-8b99-34108bbee9f6

📥 Commits

Reviewing files that changed from the base of the PR and between 9058723 and fb11527.

📒 Files selected for processing (1)
  • nc_py_api/_exceptions.py

Comment thread nc_py_api/_exceptions.py
"""Exceptions for the Nextcloud API."""

from niquests import HTTPError, Response
from niquests import AsyncResponse, HTTPError, Response
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Is AsyncResponse exported from the top-level niquests package (e.g. from niquests import AsyncResponse)? What niquests version added it?

💡 Result:

Yes. Niquests exports AsyncResponse from the top-level package, so from niquests import AsyncResponse works, as reflected in Niquests’ API documentation which lists AsyncResponse as an autoclass in the main API docs alongside the top-level interface. [1] Version: I could not find a specific release note/tag that explicitly states “exported AsyncResponse” or the version where AsyncResponse was introduced. However, Niquests’ HISTORY notes that AsyncSession “now returns a AsyncResponse when stream is set to True” (i.e., the async streaming response type existed by the time of that change), but the HISTORY snippet retrieved does not include the version number for that change. [2]

Citations:


_exceptions.py: from niquests import AsyncResponse appears to be a supported top-level export—Niquests’ API docs list AsyncResponse for the main package namespace, so this import should resolve. Since no exact “introduced in version X” release note was found, consider pinning a specific niquests version (or adding a fallback import) to avoid an ImportError if older 3.x releases ever lacked the re-export.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nc_py_api/_exceptions.py` at line 3, The import may fail on older niquests
releases because AsyncResponse may not be re-exported; update the code to handle
that by adding a fallback import or pinning niquests: either pin niquests to a
version known to export AsyncResponse in your dependency manifest, or modify the
import in _exceptions.py to try the current top-level import of AsyncResponse,
HTTPError, Response and on ImportError fall back to the module path that
actually defines AsyncResponse (e.g., the internal async submodule) so the
symbols AsyncResponse, HTTPError, and Response are always available.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.67%. Comparing base (9058723) to head (fb11527).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #439   +/-   ##
=======================================
  Coverage   94.67%   94.67%           
=======================================
  Files          48       48           
  Lines        5636     5636           
=======================================
  Hits         5336     5336           
  Misses        300      300           
Files with missing lines Coverage Δ
nc_py_api/_exceptions.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant