Skip to content

fix: allow CircuitPython UART construction without parity - #317

Open
YashAnand69 wants to merge 2 commits into
fossasia:mainfrom
YashAnand69:fix/busio-uart-default-parity
Open

YashAnand69 wants to merge 2 commits into
fossasia:mainfrom
YashAnand69:fix/busio-uart-default-parity

Conversation

@YashAnand69

@YashAnand69 YashAnand69 commented Oct 11, 2026 •

Copy link
Copy Markdown

The CircuitPython-compatible UART defaults to parity=None, but its constructor reads parity.value unconditionally. Default construction and the supported nine-bit/no-parity configuration therefore fail with AttributeError after setting the baud rate.

Apply the parity offset only when parity is supplied. This preserves the existing eight- and nine-bit no-parity modes, explicit even/odd parity, stop-bit encoding and older-firmware fallback. The regression tests check the actual command sequence and restore the cached UART configuration between cases.

Validation: five no-parity regressions fail on unchanged main; all 11 focused cases and 34 available tests pass with the fix. Configured source Black, Flake8, Bandit and pydocstyle, wheel/sdist builds and Sphinx documentation pass (seven existing documentation warnings). Scoped busio coverage increases with the same test selection. No physical PSLab or complete hardware integration run is claimed.

Prepared with Codex assistance; the change and command-level regressions were reviewed against the current firmware mode encoding.

Summary by Sourcery

Fix UART configuration to handle absent parity while retaining existing mode validation and encoding behavior.

Bug Fixes:

  • Allow CircuitPython-compatible UART construction with omitted parity, including default and nine-bit configurations.
  • Preserve UART mode handling for explicit parity, stop-bit combinations, and older firmware fallback.

Tests:

  • Add hardware-independent regression coverage for UART parity, stop-bit, firmware fallback, and invalid nine-bit parity configurations.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed UART configuration for connections that do not use parity, including default and nine-bit modes. Existing even and odd parity configurations remain supported.

@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Sorry @YashAnand69, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 17 hours and 28 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes CircuitPython-compatible UART construction with the default parity=None by conditionally applying the parity mode offset, while adding mocked command-level regressions covering no-parity, explicit parity, stop bits, nine-bit validation, cached configuration, and older firmware.

Flow diagram for UART parity mode encoding

flowchart TD
    A[UART construction] --> B[Set baud rate and base mode]
    B --> C{parity is None}
    C -->|Yes| D[Keep base mode unchanged]
    C -->|No| E[Add parity.value offset]
    D --> F[_set_uart_mode]
    E --> F
    F --> G[UART configured]
Loading

File-Level Changes

Change Details Files
Guard parity encoding so no-parity UART configurations do not dereference a missing enum value.
  • Apply the parity offset only when an explicit parity option is provided.
  • Preserve existing stop-bit, data-width, explicit even/odd parity, and older-firmware behavior.
pslab/bus/busio.py
Add hardware-independent regression coverage for UART mode encoding and configuration side effects.
  • Verify default and nine-bit no-parity command sequences and cached mode state.
  • Verify stop-bit combinations, explicit parity combinations, nine-bit parity rejection, and older-firmware fallback.
  • Restore process-wide cached UART configuration between tests.
tests/test_busio_uart_configuration.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0aa03108-4da9-49a7-a3e7-7bfe70df6c08

📥 Commits

Reviewing files that changed from the base of the PR and between 08de0d0 and cb2ac29.


📒 Files selected for processing (2)
  • pslab/bus/busio.py
  • tests/test_busio_uart_configuration.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

UART initialization now adds parity configuration only when a parity value is supplied. New mocked tests cover no-parity configurations, parity encodings, older-firmware behavior, and invalid parity with nine data bits.

Changes

UART Configuration

Layer / File(s) Summary
UART parity configuration and regression tests
pslab/bus/busio.py, tests/test_busio_uart_configuration.py
UART.__init__ adds the parity value only when parity is supplied. Mocked tests cover no-parity mode encoding, even and odd parity, older-firmware behavior, and rejection of parity with nine data bits.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix


Merge Risk: ⚪ Minimal · up to cb2ac

No actionable merge risk remains from the reviewed UART changes; merge after normal checks.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: fixing CircuitPython UART construction when no parity is provided.
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

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

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

This branch has not been deployed

No deployments
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