← Back to issue list

refactor: Replace Python 3.10 workaround for enum value checking

View original Github issue

Metadata

Project
craft-platforms
Number
#233
Type
issue
State
open
Author
lengau
Labels
—
Created
Updated
Closed
—

Current evaluation

Maintainer refactor: replace try/except ValueError DebianArchitecture validation with direct enum-value membership check. The workaround is still present at HEAD in craft_platforms/_platforms.py:93 (and a twin at charm/_build.py:260).

Suggested action: keep open

Reason: The workaround the issue targets is verifiably still at HEAD: craft_platforms/_platforms.py:93 carries the exact '# This is a workaround for Python 3.10.' comment quoted in the body, and the proposed replacement is a drop-in one-liner compatible with the declared floor (pyproject.toml requires-python = ">=3.8", so `in enum` at 3.12 is not yet available). Existing unit tests already assert the resulting error messages (tests/unit/test_platforms.py:349, tests/unit/rock/test_build.py:288), so the change is verifiable without new fixtures. Minor open question: the issue names only _platforms.py while an identical workaround also exists at craft_platforms/charm/_build.py:260, so the scope of the change is slightly ambiguous; also noted that a generator expression is O(n) per iteration versus a hoisted set, which is a minor design nit, not a blocker.

Evaluated by: mr-cal-bot

Impact: 20 Quick Win: 16 Complexity: 10 Confidence: 88 Actionability: 88

Issue body

In `craft_platforms/_platforms.py`, the codebase uses `try...except ValueError` to check if `platform_name` is a valid Debian Architecture, with the comment: ```python # This is a workaround for Python 3.10. # In python 3.12+ we can just check: # `if platform_name not in _architectures.DebianArchitecture` ``` Even in older Python versions (like Python 3.8+), we can query the enum values directly without control flow using `try...except`: ```python if platform_name not in (arch.value for arch in _architectures.DebianArchitecture): raise _errors.InvalidDebianArchPlatformNameError(platform_name) ``` We should simplify this to make the intent clearer.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha
Impact: 20
Quick Win: 16
Complexity: 10
Confidence: 88
Actionability: 88
keep open Maintainer refactor: replace try/except ValueError DebianArchitecture validation with direct enum-value membership check. The workaround is still present at HEAD in craft_platforms/_platforms.py:93 (and a twin at charm/_build.py:260).
stealth/space-bunny-alpha
Impact: 30
Quick Win: 24
Complexity: 15
Confidence: 97
Actionability: 95
needs triage Open maintainer refactor request to replace Python 3.10-era exception-based Debian architecture validation with direct enum-value membership; the workaround remains present at HEAD.
qwen3.6-35b-a3b-mtp-q6
Impact: 10
Quick Win: 9
Staleness: 65
Complexity: 10
Confidence: 80
Support Request: 0
needs triage Refactor craft-platforms to replace a Python 3.10 try/except workaround for enum checking with a direct generator expression.
qwen/qwen3.6-35b-a3b
Staleness: 40
Complexity: 10
Confidence: 90
Support Request: 0
keep open Refactoring task to replace a Python 3.10 enum workaround with a cleaner check. No comments, 36 days old.
qwen3.6-35b-a3b-mtp-q6
Staleness: 25
Complexity: 10
Confidence: 85
Support Request: 0
needs triage Refactor to replace a Python 3.10 workaround for checking enum values with a clearer generator expression. Currently unlabelled and awaiting maintainer review.

Update history

No update history recorded yet.

Related issues

No related issues found above the similarity threshold.