Skip to content

Fix bytes|str narrowing in HSA2 bridge; add types-requests dev dep#245

Open
MrJarnould wants to merge 1 commit into
timlaing:mainfrom
MrJarnould:fix/pyrefly-base-py-type-fixes
Open

Fix bytes|str narrowing in HSA2 bridge; add types-requests dev dep#245
MrJarnould wants to merge 1 commit into
timlaing:mainfrom
MrJarnould:fix/pyrefly-base-py-type-fixes

Conversation

@MrJarnould
Copy link
Copy Markdown

@MrJarnould MrJarnould commented May 15, 2026

Proposed change

Clears three Pyrefly diagnostics in pyicloud/base.py with no runtime behavior change:

  • bad-argument-type — wraps self.session.headers.get("User-Agent", _HEADERS["User-Agent"]) in typing.cast(str, ...) at the TrustedDeviceBridgeBootstrapper.start() call site. requests.Session.headers (a CaseInsensitiveDict) is typed as returning bytes | str, but start() requires str. In practice the header is always a str at runtime; the cast narrows the type without changing behavior.
  • untyped-import ×2 — adds types-requests>=2.32.0 to requirements_test.txt so type checkers have stubs for the requests library (no longer warns on requests / requests.models imports).

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New service (thank you!)
  • New feature (which adds functionality to an existing service)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests
  • Documentation or code sample

Additional information

  • This PR fixes or closes issue: N/A
  • This PR is related to issue: N/A

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works. (No new test surface — cast is identity at runtime; the existing 2FA / HSA2 bridge tests exercise the call path.)

🤖 Generated with Claude Code

- pyicloud/base.py: Wrap `self.session.headers.get("User-Agent", _HEADERS["User-Agent"])`
  in `typing.cast(str, ...)`. `requests.Session.headers` (a `CaseInsensitiveDict`) is typed
  as returning `bytes | str`, but `TrustedDeviceBridgeBootstrapper.start()` requires `str`.
  In practice the header is always a str at runtime; the cast narrows the type without
  changing behavior.
- requirements_test.txt: Add `types-requests>=2.32.0` so type checkers have stubs for the
  `requests` library and stop emitting `untyped-import` warnings.

Resolves three Pyrefly diagnostics in base.py:
- `bad-argument-type` on the `user_agent=` argument
- `untyped-import` for `requests`
- `untyped-import` for `requests.models`

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Warning

Rate limit exceeded

@MrJarnould has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 52 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fbf881a-d243-4ae3-b1a4-af4258548924

📥 Commits

Reviewing files that changed from the base of the PR and between 29315db and b0ecb34.

📒 Files selected for processing (2)
  • pyicloud/base.py
  • requirements_test.txt
✨ 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.

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