Skip to content

Commit

Permalink
Resolve ANN102 (#2149)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
Co-authored-by: Jirka <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2023
1 parent fdaab96 commit b4688d6
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 68 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ ignore = [
"D104", # todo: Missing docstring in public package
"D107", # Missing docstring in `__init__`
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod
"S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue # todo
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected. # todo
"B905", # todo: `zip()` without an explicit `strict=` parameter
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -484,7 +484,7 @@ class Accuracy(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["Accuracy"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/auroc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Sequence, Union
from typing import Any, List, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -502,7 +502,7 @@ class AUROC(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["AUROC"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/average_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Sequence, Union
from typing import Any, List, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -512,7 +512,7 @@ class AveragePrecision(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["AveragePrecision"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/calibration_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Sequence, Union
from typing import Any, List, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -368,7 +368,7 @@ class CalibrationError(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["CalibrationError"],
task: Literal["binary", "multiclass"],
n_bins: int = 15,
norm: Literal["l1", "l2", "max"] = "l1",
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/cohen_kappa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -312,7 +312,7 @@ class labels.
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["CohenKappa"],
task: Literal["binary", "multiclass"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/confusion_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional
from typing import Any, List, Optional, Type

import torch
from torch import Tensor
Expand Down Expand Up @@ -505,7 +505,7 @@ class ConfusionMatrix(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["ConfusionMatrix"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/exact_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

import torch
from torch import Tensor
Expand Down Expand Up @@ -393,7 +393,7 @@ class ExactMatch(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["ExactMatch"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 deletions src/torchmetrics/classification/f_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -1053,7 +1053,7 @@ class FBetaScore(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["FBetaScore"],
task: Literal["binary", "multiclass", "multilabel"],
beta: float = 1.0,
threshold: float = 0.5,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ class F1Score(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["F1Score"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/hamming.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -493,7 +493,7 @@ class HammingDistance(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["HammingDistance"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/hinge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

import torch
from torch import Tensor
Expand Down Expand Up @@ -351,7 +351,7 @@ class HingeLoss(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["HingeLoss"],
task: Literal["binary", "multiclass"],
num_classes: Optional[int] = None,
squared: bool = False,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/jaccard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -442,7 +442,7 @@ class JaccardIndex(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["JaccardIndex"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/matthews_corrcoef.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -390,7 +390,7 @@ class MatthewsCorrCoef(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["MatthewsCorrCoef"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/precision_fixed_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Sequence, Tuple, Union
from typing import Any, List, Optional, Sequence, Tuple, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -482,7 +482,7 @@ class PrecisionAtFixedRecall(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["PrecisionAtFixedRecall"],
task: Literal["binary", "multiclass", "multilabel"],
min_recall: float,
thresholds: Optional[Union[int, List[float], Tensor]] = None,
Expand Down
6 changes: 3 additions & 3 deletions src/torchmetrics/classification/precision_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -925,7 +925,7 @@ class Precision(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["Precision"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down Expand Up @@ -988,7 +988,7 @@ class Recall(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["Recall"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/precision_recall_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Tuple, Union
from typing import Any, List, Optional, Tuple, Type, Union

import torch
from torch import Tensor
Expand Down Expand Up @@ -650,7 +650,7 @@ class PrecisionRecallCurve(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["PrecisionRecallCurve"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/recall_fixed_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Sequence, Tuple, Union
from typing import Any, List, Optional, Sequence, Tuple, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -481,7 +481,7 @@ class RecallAtFixedPrecision(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["RecallAtFixedPrecision"],
task: Literal["binary", "multiclass", "multilabel"],
min_precision: float,
thresholds: Optional[Union[int, List[float], Tensor]] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/roc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Tuple, Union
from typing import Any, List, Optional, Tuple, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -559,7 +559,7 @@ class ROC(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["ROC"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/specificity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Optional, Sequence, Union
from typing import Any, Optional, Sequence, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -474,7 +474,7 @@ class Specificity(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["Specificity"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/specificity_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, List, Optional, Tuple, Union
from typing import Any, List, Optional, Tuple, Type, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -343,7 +343,7 @@ class SpecificityAtSensitivity(_ClassificationTaskWrapper):
"""

def __new__( # type: ignore[misc]
cls,
cls: Type["SpecificityAtSensitivity"],
task: Literal["binary", "multiclass", "multilabel"],
min_sensitivity: float,
thresholds: Optional[Union[int, List[float], Tensor]] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/classification/stat_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Any, Callable, List, Optional, Tuple, Union
from typing import Any, Callable, List, Optional, Tuple, Type, Union

import torch
from torch import Tensor
Expand Down Expand Up @@ -513,7 +513,7 @@ class StatScores(_ClassificationTaskWrapper):
"""

def __new__(
cls,
cls: Type["StatScores"],
task: Literal["binary", "multiclass", "multilabel"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
Loading

0 comments on commit b4688d6

Please sign in to comment.