Skip to content

Add flight_number field to Flight schema#93

Open
scottyallen wants to merge 1 commit intoAWeirdDev:mainfrom
scottyallen:flight-numbers
Open

Add flight_number field to Flight schema#93
scottyallen wants to merge 1 commit intoAWeirdDev:mainfrom
scottyallen:flight-numbers

Conversation

@scottyallen
Copy link

@scottyallen scottyallen commented Jan 18, 2026

Summary

  • Add flight_number: Optional[str] = None field to the Flight dataclass in schema.py
  • Add extraction logic in core.py to attempt to parse flight numbers from HTML

Context

The JS data source (decoder.py) already includes flight numbers in its Flight class, but the HTML-based Result.Flight class in schema.py was missing this field. This PR adds the field for schema consistency.

Notes

  • The HTML parser extraction uses span.Xsgmwe selector, but Google Flights doesn't expose flight numbers in the collapsed list view HTML
  • Flight numbers are only reliably available via the JS data source (data_source='js')
  • This change maintains backwards compatibility as flight_number defaults to None

Test plan

  • Verified schema.py change compiles
  • Verified core.py change doesn't break existing parsing
  • Tested with data_source='js' to confirm flight numbers are available

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Flight results now include flight number information for enhanced flight identification and tracking.
  • Bug Fixes

    • Enhanced error handling for stops parsing with automatic fallback when data is unavailable.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add flight_number: Optional[str] = None to Flight dataclass
- Extract flight number from span.Xsgmwe in parse_response()
- Flight numbers appear as "F9 1230" or "UA 820" format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 18, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

The changes add flight number tracking to the flight parsing system by introducing a new optional flight_number field to the Flight schema and implementing extraction logic that captures flight numbers from flight detail elements. Error handling is added for stops data validation.

Changes

Cohort / File(s) Summary
Flight Number Schema Extension
fast_flights/schema.py
Adds optional flight_number: Optional[str] = None field to Flight dataclass
Flight Number Extraction & Stops Fallback
fast_flights/core.py
Extracts flight_number from span.Xsgmwe element and includes it in flight dictionaries; adds ValueError fallback handling when converting stops to integer, defaulting to "Unknown"

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

✈️ A new field hops in, so light and so fleet,
Flight numbers captured, the data's complete!
When stops parse fails, we gracefully say "Unknown,"
Our schema extends, new seeds have been sown! 🐰

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 a flight_number field to the Flight schema, which is the primary modification across both modified files.

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

✨ Finishing touches
  • 📝 Generate docstrings

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 Jan 18, 2026
Copy link

@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: 0

Caution

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

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

277-280: Type mismatch: stops_fmt = "Unknown" is incompatible with Flight.stops: int.

When ValueError is raised, stops_fmt is set to the string "Unknown", but the Flight dataclass expects stops to be an int. This will cause a type inconsistency when constructing Flight(**fl) on line 301.

Consider one of these fixes:

  1. Use a sentinel integer value (e.g., -1) to indicate unknown stops
  2. Update Flight.stops to Union[int, str] or Optional[int] if "Unknown" is a valid semantic value
🐛 Proposed fix using sentinel value
             try:
                 stops_fmt = 0 if stops == "Nonstop" else int(stops.split(" ", 1)[0])
             except ValueError:
-                stops_fmt = "Unknown"
+                stops_fmt = -1  # Sentinel for unknown stops

Alternatively, if "Unknown" has semantic meaning, update the schema:

# In schema.py
-    stops: int
+    stops: Union[int, str]

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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant