Skip to content

refactor: replace get_env_vars() tuple with frozen EvergreenConfig dataclass#525

Merged
jmeridth merged 3 commits intomainfrom
jm_refactor_env_vars_to_dataclass
Mar 30, 2026
Merged

refactor: replace get_env_vars() tuple with frozen EvergreenConfig dataclass#525
jmeridth merged 3 commits intomainfrom
jm_refactor_env_vars_to_dataclass

Conversation

@jmeridth
Copy link
Copy Markdown
Collaborator

@jmeridth jmeridth commented Mar 29, 2026

Pull Request

Fixes #527

Proposed Changes

What

Replace the 30-element tuple returned by get_env_vars() with a frozen=True EvergreenConfig dataclass. Updated evergreen.py main() to use config.attribute access instead of tuple destructuring, and converted all 20 expected_result tuples in test_env.py to use named EvergreenConfig construction.

Why

The 30-element tuple was fragile — adding or removing fields required counting positions across 20+ tests, and positional access like result[8] was unreadable. Named attribute access eliminates these problems and makes future field additions trivial (just add a field with a default value).

Notes

  • This is a pure refactor with no behavior change.
  • The dataclass uses frozen=True for immutability, matching the previous tuple's semantics.
  • pylint: disable=too-many-instance-attributes is necessary since the config genuinely has 30 fields. This is inherent to the problem domain, not a design issue.
  • The main() function in evergreen.py is pragma: no cover, so switching from destructuring to config.attr access is verified by the type checker (mypy) rather than unit tests.

Testing

  • 173 tests pass with 99% code coverage, identical to before the refactor.
  • All 20 tuple-comparison tests in test_env.py converted to named EvergreenConfig(...) construction — verifies the dataclass fields match the function's return values exactly.
  • All 21 error/validation tests in test_env.py unchanged and passing.

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

@jmeridth
Copy link
Copy Markdown
Collaborator Author

jmeridth commented Mar 29, 2026

Fixing conflicts and issues after other PR merged. done

…enConfig dataclass

## What

Replace the 30-element tuple returned by get_env_vars() with a frozen dataclass EvergreenConfig. Updated evergreen.py main() to use config.attribute access instead of tuple destructuring, and converted all 20 expected_result tuples in test_env.py to use named EvergreenConfig construction. Includes the ghe_api_url field from PR #524.

## Why

The 30-element tuple was fragile — adding/removing fields required counting positions across 20+ tests, and positional access like result[8] was unreadable. Named attribute access eliminates these problems and makes future field additions trivial.

## Notes

- This is a pure refactor with no behavior change. All 173 tests pass with identical coverage.
- The dataclass uses frozen=True for immutability, matching the previous tuple's semantics.
- pylint disable for too-many-instance-attributes is necessary since the config genuinely has 30 fields.
- Rebased on main after PR #524 merge to include ghe_api_url field.

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth force-pushed the jm_refactor_env_vars_to_dataclass branch from c0ea814 to 40d1f30 Compare March 29, 2026 19:02
## What

Changed group_dependencies, enable_security_updates, and update_existing from bool | None to bool in the EvergreenConfig dataclass.

## Why

get_bool_env_var() always returns bool, never None. The overly permissive annotations were carried over from the old tuple type hints.

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth jmeridth marked this pull request as ready for review March 29, 2026 19:25
@jmeridth jmeridth requested a review from zkoppert as a code owner March 29, 2026 19:25
Copilot AI review requested due to automatic review settings March 29, 2026 19:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors environment configuration handling by replacing the large positional tuple returned by get_env_vars() with an immutable EvergreenConfig dataclass, improving readability and reducing brittleness across the action and tests.

Changes:

  • Introduce EvergreenConfig (frozen=True) and update env.get_env_vars() to return it.
  • Update evergreen.py to use config.<field> access instead of tuple destructuring.
  • Update test_env.py expected values to construct EvergreenConfig(...) and replace tuple indexing with attribute access.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
env.py Adds EvergreenConfig dataclass and changes get_env_vars() to return it.
evergreen.py Switches main flow from tuple unpacking to dataclass attribute access.
test_env.py Converts tuple-based expected results and indexing assertions to EvergreenConfig usage.

## What

Changed search_query from str | None to str, and repo_specific_exemptions from bare dict to dict[str, list[str]] in EvergreenConfig.

## Why

search_query always comes from os.getenv(..., "").strip() which never returns None. repo_specific_exemptions is built by parse_repo_specific_exemptions() which always returns dict[str, list[str]]. The tighter annotations improve IDE hints and mypy coverage.

Signed-off-by: jmeridth <jmeridth@gmail.com>
Copy link
Copy Markdown
Collaborator

@zkoppert zkoppert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I was initially wary of the type narrowing thinking that the change might cause a difference in conditional evaluations but looking through each one, it appears they were never a None value anyways. 👍🏻

@jmeridth jmeridth merged commit d2bea41 into main Mar 30, 2026
35 checks passed
@jmeridth jmeridth deleted the jm_refactor_env_vars_to_dataclass branch March 30, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor get_env_vars() return tuple to a dataclass

3 participants