Skip to content

feat: Add optional URL return to get_flights and fetch_flights_html functions#104

Open
chaurasiayush wants to merge 1 commit intoAWeirdDev:devfrom
chaurasiayush:feature-url-return
Open

feat: Add optional URL return to get_flights and fetch_flights_html functions#104
chaurasiayush wants to merge 1 commit intoAWeirdDev:devfrom
chaurasiayush:feature-url-return

Conversation

@chaurasiayush
Copy link
Copy Markdown

@chaurasiayush chaurasiayush commented Apr 4, 2026

Summary

Enhances the get_flights() and fetch_flights_html() functions to optionally return the final request URL alongside the flight data, enabling better debugging and URL sharing capabilities.

Changes

  • Added return_url parameter to get_flights() function (default: False for backward compatibility)
  • Modified fetch_flights_html() to return a tuple of (html, url) instead of just html
  • Added proper type hints with Literal types for overloaded function signatures
  • Updated function signatures to support both return types:
    • return_url=False (default): Returns MetaList only
    • return_url=True: Returns tuple[MetaList, str] with flights and URL

Benefits

  • Backward Compatible: Existing code continues to work without changes
  • Better Debugging: Developers can now access the actual Google Flights URL used for the query
  • URL Sharing: Users can share or inspect the exact URL being queried
  • Type Safety: Proper overloads ensure type checkers understand both return patterns

Example Usage

# Default behavior (backward compatible)
flights = get_flights(query)

# New behavior with URL
flights, url = get_flights(query, return_url=True)
print(f"Query URL: {url}")


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added optional parameter to retrieve flight search source URL alongside flight results, enabling users to access the original query URL when needed.
  * Default behavior remains unchanged, maintaining full backward compatibility with existing code.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Updated the get_flights function to include a return_url parameter, allowing it to optionally return a tuple of flights and URL. Modified fetch_flights_html to return both HTML and the final URL.
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

The pull request adds a return_url parameter to get_flights with Literal-based overloads that conditionally return either MetaList or a tuple of (MetaList, str). The fetch_flights_html function's return type is updated from str to tuple[str, str] to include the response URL alongside the HTML content.

Changes

Cohort / File(s) Summary
Flight Fetcher API Enhancement
fast_flights/fetcher.py
Added return_url parameter with Literal[False]/Literal[True] overloads to get_flights, enabling conditional return of flights URL. Updated fetch_flights_html return type to tuple[str, str] to provide both HTML and URL. Modified implementation to handle tuple unpacking and conditional return logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops of joy for URLs bright,
No more guessing flight's domain—
Overloads type-safe and tight,
Fetch returns with gentle rain,
Data flows both left and right!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding an optional URL return capability to two functions. It is concise, specific, and directly reflects the primary modification in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@dosubot dosubot bot added the enhancement New feature or request label Apr 4, 2026
@chaurasiayush
Copy link
Copy Markdown
Author

chaurasiayush commented Apr 4, 2026

implements feature request #33

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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
fast_flights/fetcher.py (1)

12-105: ⚠️ Potential issue | 🟠 Major

Overloads are missing the integration parameter.

The actual implementation at line 112 accepts integration: Integration | None = None, but none of the four overloads include this parameter. This means type checkers will reject valid calls like:

get_flights(query, integration=my_integration, return_url=True)

Either add corresponding overloads that include the integration parameter, or document that integration is intentionally excluded from the public typed API.

Example fix for one overload pair
 `@overload`
 def get_flights(
     q: Query,
     /,
     *,
     proxy: str | None = None,
+    integration: Integration | None = None,
     return_url: Literal[True],
 ) -> tuple[MetaList, str]:

Repeat for all four overloads.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fast_flights/fetcher.py` around lines 12 - 105, The four get_flights
overloads are missing the integration parameter present in the implementation;
update each overload signature to include integration: Integration | None = None
(placed after proxy: str | None = None and before return_url) so type-checkers
accept calls like get_flights(query, integration=my_integration,
return_url=True); ensure all four overload variants (str/q variants with
return_url True/False) are updated consistently to match the runtime signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fast_flights/fetcher.py`:
- Around line 170-172: The integration branch currently returns only the base
URL constant (URL) which omits query parameters; update the integration path in
the fetch logic so it returns the full request URL (including query string)
along with the fetched HTML — either by changing integration.fetch_html(q) to
return a tuple (html, full_url) or by constructing the URL the same way
bright_data does (see bright_data.build/construct logic) and return that full
URL instead of the bare URL constant; ensure the calling code that handles the
other branch (which expects (html, URL)) still receives the same (html,
full_url) shape.
- Line 141: fetch_flights_html was changed to return (html, url) breaking
callers that expect a single string; restore backward compatibility by adding an
optional parameter (e.g., return_url: bool = False) to fetch_flights_html and
branch the return: when return_url is False return the html string (old
behavior) and when True return the (html, url) tuple, update the function
signature/type hints and docstring to describe the parameter and both return
shapes (or provide typed overloads), and update tests/docs; alternatively, if
you choose to keep the new tuple-only API, add a clear release note/migration
guide calling out fetch_flights_html change so callers can adapt.

---

Outside diff comments:
In `@fast_flights/fetcher.py`:
- Around line 12-105: The four get_flights overloads are missing the integration
parameter present in the implementation; update each overload signature to
include integration: Integration | None = None (placed after proxy: str | None =
None and before return_url) so type-checkers accept calls like
get_flights(query, integration=my_integration, return_url=True); ensure all four
overload variants (str/q variants with return_url True/False) are updated
consistently to match the runtime signature.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90b0f68b-20f1-4d43-b681-02dc71c803d5

📥 Commits

Reviewing files that changed from the base of the PR and between 0138641 and c3c5c9d.

📒 Files selected for processing (1)
  • fast_flights/fetcher.py

Comment thread fast_flights/fetcher.py
integration: Integration | None = None,
) -> str:
"""Fetch flights and get the **HTML**.
) -> tuple[str, str]:
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if fetch_flights_html is exported publicly and used externally

# Check __init__.py exports
echo "=== Checking public exports ==="
cat fast_flights/__init__.py 2>/dev/null || echo "__init__.py not found"

# Search for external usage patterns of fetch_flights_html
echo -e "\n=== Searching for fetch_flights_html usage ==="
rg -n "fetch_flights_html" --type py -C2

Repository: AWeirdDev/flights

Length of output: 1515


🏁 Script executed:

#!/bin/bash

# Get the full function signature and implementation
echo "=== Full fetch_flights_html function ==="
sed -n '135,168p' fast_flights/fetcher.py

# Check for docstrings
echo -e "\n=== Checking for docstrings ==="
sed -n '135,155p' fast_flights/fetcher.py | grep -A 20 '"""'

# Search for tests related to fetch_flights_html
echo -e "\n=== Searching for tests ==="
find . -type f -name "*test*.py" -o -name "test_*" | head -20
rg -n "fetch_flights_html" --type py tests/ 2>/dev/null || echo "No tests found"

# Check for any changelog or documentation about this change
echo -e "\n=== Checking changelog/docs ==="
fd -e md -e rst -e txt | xargs grep -l "fetch_flights_html" 2>/dev/null || echo "No docs mention found"

Repository: AWeirdDev/flights

Length of output: 1478


Breaking change: fetch_flights_html return type changed from str to tuple[str, str].

The function is publicly exported and now returns a tuple of (html, url) instead of just the HTML string. External callers expecting a string will break:

# Code that worked before will now fail:
html = fetch_flights_html(query)  # Now returns tuple, not string

The return type is documented in the function's docstring, but this breaking change lacks a release note or migration guide. Consider either:

  1. Adding a return_url parameter to maintain backward compatibility, or
  2. Documenting this as a breaking change in release notes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fast_flights/fetcher.py` at line 141, fetch_flights_html was changed to
return (html, url) breaking callers that expect a single string; restore
backward compatibility by adding an optional parameter (e.g., return_url: bool =
False) to fetch_flights_html and branch the return: when return_url is False
return the html string (old behavior) and when True return the (html, url)
tuple, update the function signature/type hints and docstring to describe the
parameter and both return shapes (or provide typed overloads), and update
tests/docs; alternatively, if you choose to keep the new tuple-only API, add a
clear release note/migration guide calling out fetch_flights_html change so
callers can adapt.

Comment thread fast_flights/fetcher.py
Comment on lines 170 to +172
else:
return integration.fetch_html(q)
html = integration.fetch_html(q)
return html, URL
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 | 🟠 Major

Integration branch returns incomplete URL without query parameters.

The direct fetch path (line 168) returns str(res.url) which includes the full URL with query parameters. However, the integration branch returns only the base URL constant ("https://www.google.com/travel/flights"), omitting query parameters entirely.

This inconsistency undermines the debugging/sharing purpose of returning the URL. Users would expect the full request URL, not just the base endpoint.

Suggested fix
     else:
         html = integration.fetch_html(q)
-        return html, URL
+        if isinstance(q, Query):
+            return html, q.url()
+        else:
+            return html, f"{URL}?q={q}"

This mirrors how bright_data.py constructs URLs internally (per relevant snippet at fast_flights/integrations/bright_data.py:38-48).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
else:
return integration.fetch_html(q)
html = integration.fetch_html(q)
return html, URL
else:
html = integration.fetch_html(q)
if isinstance(q, Query):
return html, q.url()
else:
return html, f"{URL}?q={q}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@fast_flights/fetcher.py` around lines 170 - 172, The integration branch
currently returns only the base URL constant (URL) which omits query parameters;
update the integration path in the fetch logic so it returns the full request
URL (including query string) along with the fetched HTML — either by changing
integration.fetch_html(q) to return a tuple (html, full_url) or by constructing
the URL the same way bright_data does (see bright_data.build/construct logic)
and return that full URL instead of the bare URL constant; ensure the calling
code that handles the other branch (which expects (html, URL)) still receives
the same (html, full_url) shape.

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

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant