Skip to content

Conversation

@KRRT7
Copy link
Contributor

@KRRT7 KRRT7 commented May 27, 2025

User description

Crosshair needs the type hints to be reachable, we can avoid a subprocess call by just defensively checking if all the nodes have their type hints reachable


PR Type

Enhancement


Description

  • Added type_hints_reachable helper function

  • Guarded concolic test generation with check

  • Added tests for type_hints_reachable behavior


Changes walkthrough 📝

Relevant files
Enhancement
static_analysis.py
Add type_hints_reachable function                                               

codeflash/code_utils/static_analysis.py

  • Import get_type_hints from typing
  • Define type_hints_reachable to test hints
  • +10/-1   
    concolic_testing.py
    Guard concolic tests with reachable hints                               

    codeflash/verification/concolic_testing.py

  • Import type_hints_reachable
  • Require reachable hints in test generation
  • +2/-1     
    Tests
    test_static_analysis.py
    Test type_hints_reachable behavior                                             

    tests/test_static_analysis.py

    • Import type_hints_reachable
    • Add unreachable hints test cases
    +15/-0   

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

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    TypeHints Reachability

    Using get_type_hints directly on an AST node may not accurately reflect whether annotations are actually resolvable at runtime and could produce false positives. Consider applying this check on real function objects or providing the correct global/local namespace context.

    def type_hints_reachable(node: ast.AST) -> bool:
        try:
            get_type_hints(node)
        except Exception:
            return False
        else:
            return True
    Unused Import

    The TypeVar symbol is imported but never used in this module. Removing it would clean up the imports.

    from typing import TYPE_CHECKING, TypeVar, get_type_hints
    Incomplete Tests

    The tests for type_hints_reachable only assert negative outcomes. Add a positive test case where an object with valid annotations returns True to ensure correct behavior.

        code7 = """
    import pandas as pd
    from typing import get_type_hints
    """
    
        assert type_hints_reachable(code7) is False
    
        code = """
    import numpy as np
    def foo(x, y):
        return x + y
    """
        assert type_hints_reachable(code) is False

    @github-actions
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Use real objects in tests

    Update tests to pass actual function or class objects (e.g. by ast.parse+exec)
    instead of raw strings so type_hints_reachable can operate on real objects.

    tests/test_static_analysis.py [110]

    -assert type_hints_reachable(code7) is False
    +namespace = {}
    +exec(code7, namespace)
    +assert type_hints_reachable(namespace.get("foo", object())) is False
    Suggestion importance[1-10]: 6

    __

    Why: Converting raw code strings into real function objects makes type_hints_reachable tests valid and improves reliability without altering core logic.

    Low

    @KRRT7 KRRT7 closed this May 27, 2025
    @KRRT7 KRRT7 deleted the concolic-beef-up branch May 27, 2025 13:58
    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.

    1 participant