Skip to content

fix: Add aiohttp conditional type checking #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ronantakizawa
Copy link

@ronantakizawa ronantakizawa commented Aug 9, 2025

Add aiohttp conditional type checking.

  • Problem: _aiter_response_stream() method referenced aiohttp.ClientResponse without checking if aiohttp
    was available, causing NameError when aiohttp wasn't installed
  • Solution: Added conditional type checking that only includes aiohttp types when has_aiohttp is True

Before the Fix:
This would ALWAYS try to reference aiohttp.ClientResponse
if not isinstance(self.response_stream, (httpx.Response, aiohttp.ClientResponse)):
❌ CRASH: NameError if aiohttp not installed

After the Fix:
Step 1: Build valid types conditionally
valid_types = (httpx.Response,) Always start with httpx
if has_aiohttp:
valid_types = (httpx.Response, aiohttp.ClientResponse) Add aiohttp if available
Step 2: Use the conditional types
if not isinstance(self.response_stream, valid_types):
✅ No crash - only references types that exist

Fixes issue #1230

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