-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,785 additions
and
929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
crates/ruff_linter/resources/test/fixtures/flake8_type_checking/singledispatch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Test module.""" | ||
from __future__ import annotations | ||
|
||
from functools import singledispatch | ||
from typing import TYPE_CHECKING | ||
|
||
from numpy import asarray | ||
from numpy.typing import ArrayLike | ||
from scipy.sparse import spmatrix | ||
from pandas import DataFrame | ||
|
||
if TYPE_CHECKING: | ||
from numpy import ndarray | ||
|
||
|
||
@singledispatch | ||
def to_array_or_mat(a: ArrayLike | spmatrix) -> ndarray | spmatrix: | ||
"""Convert arg to array or leaves it as sparse matrix.""" | ||
msg = f"Unhandled type {type(a)}" | ||
raise NotImplementedError(msg) | ||
|
||
|
||
@to_array_or_mat.register | ||
def _(a: ArrayLike) -> ndarray: | ||
return asarray(a) | ||
|
||
|
||
@to_array_or_mat.register | ||
def _(a: spmatrix) -> spmatrix: | ||
return a | ||
|
||
|
||
def _(a: DataFrame) -> DataFrame: | ||
return a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.