Skip to content

Fix ruff upgrade#173

Merged
CoMPaTech merged 1 commit intomainfrom
ruff_up_n_fix
Feb 24, 2026
Merged

Fix ruff upgrade#173
CoMPaTech merged 1 commit intomainfrom
ruff_up_n_fix

Conversation

@CoMPaTech
Copy link
Owner

@CoMPaTech CoMPaTech commented Feb 24, 2026

Fix ruff upgrade #172

Summary by CodeRabbit

  • Chores

    • Updated Ruff pre-commit hook to v0.15.2
  • Refactor

    • Improved host component normalization in URL construction
    • Refined HTTP error detection for 404 responses

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 24, 2026
@sonarqubecloud
Copy link

@coderabbitai
Copy link

coderabbitai bot commented Feb 24, 2026

Walkthrough

Ruff pre-commit hook version bumped from v0.14.14 to v0.15.2. Host URL construction normalization simplified in airos/base.py __init__ method. 404 error handling logic in _request_json changed from list membership to direct equality comparison.

Changes

Cohort / File(s) Summary
Pre-commit Configuration
.pre-commit-config.yaml
Upgraded Ruff linter hook version from v0.14.14 to v0.15.2.
Core Request Handling
airos/base.py
Simplified host normalization logic in __init__ to use parsed_host properties; changed 404 error detection from membership check (err.status in [404]) to direct equality (err.status == 404).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A version hop, from old to new,
Ruff's refinement shines right through!
Host URLs now parse with grace,
404s caught in the right place. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Fix ruff upgrade' is vague and generic, failing to clearly communicate the main changes to reviewers scanning pull request history. Consider a more descriptive title that specifies the actual changes, such as 'Upgrade Ruff to v0.15.2 and refactor host/error handling' or 'Update Ruff pre-commit hook and simplify base.py logic'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ruff_up_n_fix

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 bug Something isn't working label Feb 24, 2026
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.64%. Comparing base (9b23494) to head (cc87045).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
airos/base.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #173   +/-   ##
=======================================
  Coverage   86.64%   86.64%           
=======================================
  Files           8        8           
  Lines         749      749           
=======================================
  Hits          649      649           
  Misses        100      100           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CoMPaTech CoMPaTech merged commit 05a770b into main Feb 24, 2026
13 of 15 checks passed
@CoMPaTech CoMPaTech deleted the ruff_up_n_fix branch February 24, 2026 16:18
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@airos/base.py`:
- Around line 60-64: The current construction of self.base_url uses
parsed_host.hostname which drops explicit ports; update the logic in the url
parsing block (symbols: urlparse, parsed_host, scheme, use_ssl, hostname,
base_url) to use parsed_host.netloc (falling back to host if netloc is empty)
when composing the authority portion so ports are preserved; keep the existing
scheme selection (parsed_host.scheme or ("https" if use_ssl else "http")) and
then set self.base_url = f"{scheme}://{netloc}" (with netloc defaulting to host
when needed).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b23494 and cc87045.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • airos/base.py

Comment on lines 60 to 64
parsed_host = urlparse(host)
scheme = (
parsed_host.scheme
if parsed_host.scheme
else ("https" if use_ssl else "http")
)
hostname = parsed_host.hostname if parsed_host.hostname else host
scheme = parsed_host.scheme or ("https" if use_ssl else "http")
hostname = parsed_host.hostname or host

self.base_url = f"{scheme}://{hostname}"
Copy link

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
# First, find airos/base.py and read the relevant lines
git ls-files | grep -E 'airos.*base\.py'

Repository: CoMPaTech/python-airos

Length of output: 79


🏁 Script executed:

#!/bin/bash
# Read the code around lines 60-64 in airos/base.py to see exact implementation
find . -name 'base.py' -path '*/airos/*' -type f | head -5

Repository: CoMPaTech/python-airos

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Search for how this class is instantiated with host parameter
rg -n 'class.*\(.*\):' airos/ | grep -i base

Repository: CoMPaTech/python-airos

Length of output: 345


🏁 Script executed:

#!/bin/bash
# Read the __init__ method and surrounding code in airos/base.py
sed -n '39,100p' airos/base.py | cat -n

Repository: CoMPaTech/python-airos

Length of output: 2739


🏁 Script executed:

#!/bin/bash
# Search for instantiation of AirOS class with host parameter
rg -n 'AirOS\(' -A 2 --type=py | head -50

Repository: CoMPaTech/python-airos

Length of output: 194


🏁 Script executed:

#!/bin/bash
# Also search for test files that show how this class is used
find . -name '*test*.py' -type f | xargs grep -l 'AirOS' | head -3

Repository: CoMPaTech/python-airos

Length of output: 131


🏁 Script executed:

#!/bin/bash
# Read test files to see how host is passed
cat tests/conftest.py | head -100

Repository: CoMPaTech/python-airos

Length of output: 2155


🏁 Script executed:

#!/bin/bash
# Search for host parameter values in tests
rg -n 'host\s*=' tests/ -A 1 -B 1

Repository: CoMPaTech/python-airos

Length of output: 1650


🏁 Script executed:

#!/bin/bash
# Search for AirOS instantiation in tests showing host parameter
rg -n 'AirOS\(' tests/ -A 5 | head -80

Repository: CoMPaTech/python-airos

Length of output: 48


🏁 Script executed:

#!/bin/bash
# Search for any host parameter with explicit port numbers in the codebase
rg -n ':\d+' airos/ tests/ --type=py | grep -E '(host|url).*:\d+'

Repository: CoMPaTech/python-airos

Length of output: 48


🏁 Script executed:

#!/bin/bash
# Check if there's any documentation or examples showing port usage
find . -name 'README*' -o -name '*.md' | xargs grep -l 'port\|:\d\d\d\d' 2>/dev/null | head -5

Repository: CoMPaTech/python-airos

Length of output: 106


🏁 Script executed:

#!/bin/bash
# Let's verify the urlparse behavior with a quick Python test
python3 << 'EOF'
from urllib.parse import urlparse

# Test cases showing the difference between hostname and netloc
test_cases = [
    "192.168.1.3",
    "http://192.168.1.3",
    "https://example.com:8443",
    "http://device.local:9000",
    "device.local",
]

print("URL | hostname | netloc")
print("-" * 60)
for url in test_cases:
    parsed = urlparse(url)
    print(f"{url:30} | {parsed.hostname or 'None':20} | {parsed.netloc or 'None'}")
EOF

Repository: CoMPaTech/python-airos

Length of output: 487


Preserve explicit ports in base_url.
parsed_host.hostname drops the port (e.g., https://example.com:8443example.com), causing requests to fail for non-standard ports. Use netloc instead:

 parsed_host = urlparse(host)
 scheme = parsed_host.scheme or ("https" if use_ssl else "http")
-hostname = parsed_host.hostname or host
+netloc = parsed_host.netloc or host
-self.base_url = f"{scheme}://{hostname}"
+self.base_url = f"{scheme}://{netloc}"

Current tests pass hosts without explicit ports, so this bug is latent. However, any caller providing host with a port (e.g., via configuration or discovery) will experience connection failures.

📝 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
parsed_host = urlparse(host)
scheme = (
parsed_host.scheme
if parsed_host.scheme
else ("https" if use_ssl else "http")
)
hostname = parsed_host.hostname if parsed_host.hostname else host
scheme = parsed_host.scheme or ("https" if use_ssl else "http")
hostname = parsed_host.hostname or host
self.base_url = f"{scheme}://{hostname}"
parsed_host = urlparse(host)
scheme = parsed_host.scheme or ("https" if use_ssl else "http")
netloc = parsed_host.netloc or host
self.base_url = f"{scheme}://{netloc}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@airos/base.py` around lines 60 - 64, The current construction of
self.base_url uses parsed_host.hostname which drops explicit ports; update the
logic in the url parsing block (symbols: urlparse, parsed_host, scheme, use_ssl,
hostname, base_url) to use parsed_host.netloc (falling back to host if netloc is
empty) when composing the authority portion so ports are preserved; keep the
existing scheme selection (parsed_host.scheme or ("https" if use_ssl else
"http")) and then set self.base_url = f"{scheme}://{netloc}" (with netloc
defaulting to host when needed).

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

Labels

bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant