Skip to content

Fixing codeflash init for Python 3.9 (CF-649) #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged

Conversation

aseembits93
Copy link
Contributor

@aseembits93 aseembits93 commented May 21, 2025

User description

Using older type hints supported by Python 3.9


PR Type

Bug fix


Description

  • Added Union import for typing compatibility

  • Replaced PEP 604 type hint with Union

  • Ensures codeflash init runs on Python 3.9


Changes walkthrough 📝

Relevant files
Bug fix
cmd_init.py
Use `Union` for optional type hints                                           

codeflash/cli_cmds/cmd_init.py

  • Added Union import from typing
  • Replaced str | None with Union[str, None] for benchmarks_root
  • +2/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Unused Import

    The imports TYPE_CHECKING, Any, and cast were added but are not used in this file, which may trigger lint warnings. Consider removing unused imports.

    from typing import TYPE_CHECKING, Any, cast, Union
    Type Hint Style

    While Union[str, None] is functionally correct, using Optional[str] is more idiomatic under PEP 484 and improves readability.

    benchmarks_root: Union[str, None]

    @misrasaurabh1 misrasaurabh1 merged commit 1879e0e into main May 21, 2025
    15 of 16 checks passed
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Replace Union with Optional

    Use Optional[str] instead of Union[str, None] for clarity and brevity. Update the
    import to bring in Optional and remove Union.

    codeflash/cli_cmds/cmd_init.py [10-57]

    -from typing import TYPE_CHECKING, Any, cast, Union
    +from typing import TYPE_CHECKING, Any, cast, Optional
     
     @dataclass(frozen=True)
     class SetupInfo:
         module_root: str
         tests_root: str
    -    benchmarks_root: Union[str, None]
    +    benchmarks_root: Optional[str]
         test_framework: str
         ignore_paths: list[str]
         formatter: str
         git_remote: str
    Suggestion importance[1-10]: 5

    __

    Why: Using Optional[str] instead of Union[str, None] improves readability and conciseness in the type annotation.

    Low

    @aseembits93 aseembits93 deleted the py39-init-fix branch May 21, 2025 05:29
    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.

    2 participants