Skip to content

Instantly share code, notes, and snippets.

@rpgoldman
Last active May 2, 2024 16:48
Show Gist options
  • Select an option

  • Save rpgoldman/91b1d0b20e09a4b5f27dbf3d395a8217 to your computer and use it in GitHub Desktop.

Select an option

Save rpgoldman/91b1d0b20e09a4b5f27dbf3d395a8217 to your computer and use it in GitHub Desktop.

Revisions

  1. rpgoldman revised this gist May 2, 2024. 2 changed files with 75 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions mypy-output2.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    $ poetry run mypy dspy/evaluate/mypy_issue.py
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 4 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:23: error: Overloaded function signatures 2 and 3 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:23: error: Overloaded function signatures 2 and 4 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:33: error: Overloaded function signatures 3 and 4 overlap with incompatible return types [overload-overlap]
    Found 6 errors in 1 file (checked 1 source file)
    67 changes: 67 additions & 0 deletions mypy_issue2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    from typing import overload, Literal, List, Tuple, Any

    class Example:
    pass

    class Prediction:
    pass


    class TestMypy:

    @overload
    def __call__(
    self,
    program,
    foo: int = ...,
    return_all_scores: Literal[True] = ...,
    return_outputs: Literal[True] = ...,
    ) -> Tuple[float, List[Tuple[Example, Prediction, Any]], List[float]]:
    ...

    @overload
    def __call__(
    self,
    program,
    foo: int = ...,
    return_all_scores: Literal[True] = ...,
    return_outputs: Literal[False] = ...,
    ) -> Tuple[float, List[float]]:
    ...

    @overload
    def __call__(
    self,
    program,
    foo: int = ...,
    return_all_scores: Literal[False] = ...,
    return_outputs: Literal[True] = ...,
    ) -> Tuple[float, List[Tuple[Example, Prediction, Any]]]:
    ...

    @overload
    def __call__(
    self,
    program,
    foo: int = ...,
    return_all_scores: Literal[False] = ...,
    return_outputs: Literal[False] = ...,
    ) -> float:
    ...

    def __call__(
    self,
    program,
    foo: int = 5,
    return_all_scores: bool = False,
    return_outputs: bool = False,
    ):
    if return_all_scores:
    if return_outputs:
    return foo, [(Example(), Prediction(), 0.1)], [0.1]
    else:
    return foo, [0.1]
    elif return_outputs:
    return foo, [(Example(), Prediction(), 0.1)]
    else:
    return foo
  2. rpgoldman revised this gist May 1, 2024. 2 changed files with 8 additions and 0 deletions.
    File renamed without changes.
    8 changes: 8 additions & 0 deletions mypy-output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    $ poetry run mypy dspy/evaluate/mypy_issue.py
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:13: error: Overloaded function signatures 1 and 4 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:22: error: Overloaded function signatures 2 and 3 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:22: error: Overloaded function signatures 2 and 4 overlap with incompatible return types [overload-overlap]
    dspy/evaluate/mypy_issue.py:31: error: Overloaded function signatures 3 and 4 overlap with incompatible return types [overload-overlap]
    Found 6 errors in 1 file (checked 1 source file)
  3. rpgoldman created this gist May 1, 2024.
    62 changes: 62 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    from typing import overload, Literal, List, Tuple, Any

    class Example:
    pass

    class Prediction:
    pass


    class TestMypy:

    @overload
    def __call__(
    self,
    program,
    return_all_scores: Literal[True] = ...,
    return_outputs: Literal[True] = ...,
    ) -> Tuple[float, List[Tuple[Example, Prediction, Any]], List[float]]:
    ...

    @overload
    def __call__(
    self,
    program,
    return_all_scores: Literal[True] = ...,
    return_outputs: Literal[False] = ...,
    ) -> Tuple[float, List[float]]:
    ...

    @overload
    def __call__(
    self,
    program,
    return_all_scores: Literal[False] = ...,
    return_outputs: Literal[True] = ...,
    ) -> Tuple[float, List[Tuple[Example, Prediction, Any]]]:
    ...

    @overload
    def __call__(
    self,
    program,
    return_all_scores: Literal[False] = ...,
    return_outputs: Literal[False] = ...,
    ) -> float:
    ...

    def __call__(
    self,
    program,
    return_all_scores: bool = False,
    return_outputs: bool = False,
    ):
    if return_all_scores:
    if return_outputs:
    return 0.1, [(Example(), Prediction(), 0.1)], [0.1]
    else:
    return 0.1, [0.1]
    elif return_outputs:
    return 0.1, [(Example(), Prediction(), 0.1)]
    else:
    return 0.1