Skip to content

Minor code cleanups/modernizations recommended by ruff - #943

Merged
bradenmacdonald merged 1 commit into
openedx:mainfrom
open-craft:braden/minor-fixes
Nov 18, 2026
Merged

bradenmacdonald merged 1 commit into
openedx:mainfrom
open-craft:braden/minor-fixes

Conversation

@bradenmacdonald

@bradenmacdonald bradenmacdonald commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes a bunch of minor issues flagged by ruff linter, mostly moving from old python APIs/syntax to newer, e.g. List[str] -> list[str].

I think everything in the diff should be self explanatory.

This also fixes one pylint warning that's been showing up on main for quite some time:

************* Module openedx_content.applets.containers.models
src/openedx_content/applets/containers/models.py:163:0: I0021: Useless suppression of 'invalid-str-returned' (useless-suppression)

We're not officially using ruff as a linter for this repo, and there are some other things it's flagging that I haven't fixed here, so I haven't actually enabled/configured it in pyproject.toml. But for the record, I used:

[tool.ruff.lint]
select = ["E", "W", "I", "F", "PT", "DJ", "UP", "B"]  # same as openedx-platform
ignore = [
    "F403",  # 'from ... import *' is used extensively in this repo
]

Summary by CodeRabbit

  • Refactor
    • Updated type annotations across content backup and restore, publishing, collections, and tagging components to use modern Python syntax.
    • Clarified type information for model references, permission checks, and collection and taxonomy data.
    • No changes to user-visible functionality, backup and restore behavior, or permission-checking logic.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Nov 18, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @bradenmacdonald!

This repository is currently maintained by @axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request updates type annotations and import sources across content, learning, and tagging modules. It also makes small syntax and comment changes. The described runtime behavior remains unchanged.

Changes: Python typing modernization

Layer / File(s) Summary
Type aliases and model contracts
src/openedx_content/applets/collections/models.py, src/openedx_tagging/data.py, src/openedx_tagging/models/base.py, src/openedx_tagging/rules.py
Type aliases and the collection field annotation use built-in type syntax and direct type references.
Function and API annotations
src/openedx_content/applets/backup_restore/toml.py, src/openedx_content/applets/backup_restore/zipper.py, src/openedx_content/applets/publishing/api.py, src/openedx_tagging/models/base.py, src/openedx_tagging/rest_api/paginators.py, src/openedx_tagging/rest_api/utils.py, src/openedx_tagging/rest_api/v1/serializers.py
Annotations use built-in generics, union syntax, and more specific model and string types. Parsing, lookup, and permission-checking behavior is unchanged.
Import and syntax cleanup
src/openedx_content/applets/containers/api.py, src/openedx_content/applets/containers/models.py, src/openedx_content/applets/publishing/contextmanagers.py, src/openedx_content/applets/{sections,subsections,units}/api.py, src/openedx_content/backcompat/publishing/migrations/0007_bootstrap_draftchangelog.py, src/openedx_learning/applets/cbe/{api.py,rule_payloads.py}, src/openedx_tagging/api.py, src/openedx_tagging/migrations/0015_taxonomy_export_id.py
Collection-related imports move to standard-library modules. The changes also remove a lint suppression, simplify a log string, and remove trailing whitespace.

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

Change: Refactor

Suggested reviewers: kdmccormick, jesperhodge

Merge Risk: Minimal · up to 95e1d

This PR modernizes type annotations and imports without changing runtime behavior. No concrete regression was found, and the declared Python 3.12 floor supports the new syntax.

Security architecture risk: Minimal · up to 95e1d

The inspected changes do not introduce or worsen a material security or architecture risk. Permission checks, persistence operations, and the Python version requirement remain substantively unchanged.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Minor code cleanups/modernizations recommended by ruff" matches the changeset. The summaries show many files moved from typing generics (List, Optional, Tuple, Type, Union, Iterable, Callab…
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.
Full details: Title check

Explanation

The title "Minor code cleanups/modernizations recommended by ruff" matches the changeset. The summaries show many files moved from typing generics (List, Optional, Tuple, Type, Union, Iterable, Callable) to built-in types, collections.abc imports, PEP 604 unions, and the type statement. The title names the main theme and the tool that drove it. It is slightly broad, but it describes real changes and is not vague or off-topic.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8561696f-7e89-487c-b664-bc381ad4a3bd
Commits

Reviewing files that changed from the base of the PR and between 8b02e7c and 95e1d55.

Files selected for processing: 21

  • src/openedx_content/applets/backup_restore/toml.py
  • src/openedx_content/applets/backup_restore/zipper.py
  • src/openedx_content/applets/collections/models.py
  • src/openedx_content/applets/containers/api.py
  • src/openedx_content/applets/containers/models.py
  • src/openedx_content/applets/publishing/api.py
  • src/openedx_content/applets/publishing/contextmanagers.py
  • src/openedx_content/applets/sections/api.py
  • src/openedx_content/applets/subsections/api.py
  • src/openedx_content/applets/units/api.py
  • src/openedx_content/backcompat/publishing/migrations/0007_bootstrap_draftchangelog.py
  • src/openedx_learning/applets/cbe/api.py
  • src/openedx_learning/applets/cbe/rule_payloads.py
  • src/openedx_tagging/api.py
  • src/openedx_tagging/data.py
  • src/openedx_tagging/migrations/0015_taxonomy_export_id.py
  • src/openedx_tagging/models/base.py
  • src/openedx_tagging/rest_api/paginators.py
  • src/openedx_tagging/rest_api/utils.py
  • src/openedx_tagging/rest_api/v1/serializers.py
  • src/openedx_tagging/rules.py

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

@bradenmacdonald
bradenmacdonald merged commit d59ec45 into openedx:main Nov 18, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Contributions Nov 18, 2026
@bradenmacdonald
bradenmacdonald deleted the braden/minor-fixes branch November 18, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants