Skip to content
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

Resolve ANN102 #2149

Merged
merged 17 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 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 @@ -483,8 +483,8 @@ class Accuracy(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["Accuracy"],
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/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 @@ -501,8 +501,8 @@ class AUROC(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["AUROC"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 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 @@ -511,8 +511,8 @@ class AveragePrecision(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["AveragePrecision"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 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 @@ -367,8 +367,8 @@ class CalibrationError(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["CalibrationError"],
task: Literal["binary", "multiclass"],
n_bins: int = 15,
norm: Literal["l1", "l2", "max"] = "l1",
Expand Down
6 changes: 3 additions & 3 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 @@ -311,8 +311,8 @@ class labels.

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["CohenKappa"],
task: Literal["binary", "multiclass"],
threshold: float = 0.5,
num_classes: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 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 @@ -504,8 +504,8 @@ class ConfusionMatrix(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
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
6 changes: 3 additions & 3 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 @@ -492,8 +492,8 @@ class HammingDistance(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["HammingDistance"],
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/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 @@ -350,8 +350,8 @@ class HingeLoss(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["HingeLoss"],
task: Literal["binary", "multiclass"],
num_classes: Optional[int] = None,
squared: bool = False,
Expand Down
6 changes: 3 additions & 3 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 @@ -441,8 +441,8 @@ class JaccardIndex(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["JaccardIndex"],
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/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 @@ -389,8 +389,8 @@ class MatthewsCorrCoef(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["MatthewsCorrCoef"],
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/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 @@ -481,8 +481,8 @@ class PrecisionAtFixedRecall(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
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
6 changes: 3 additions & 3 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 @@ -649,8 +649,8 @@ class PrecisionRecallCurve(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["PrecisionRecallCurve"],
task: Literal["binary", "multiclass", "multilabel"],
thresholds: Optional[Union[int, List[float], Tensor]] = None,
num_classes: Optional[int] = None,
Expand Down
6 changes: 3 additions & 3 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 @@ -480,8 +480,8 @@ class RecallAtFixedPrecision(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
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
6 changes: 3 additions & 3 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 @@ -473,8 +473,8 @@ class Specificity(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["Specificity"],
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/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 @@ -342,8 +342,8 @@ class SpecificityAtSensitivity(_ClassificationTaskWrapper):

"""

def __new__( # type: ignore[misc]
cls,
def __new__(
cls: Type["SpecificityAtSensitivity"],
task: Literal["binary", "multiclass", "multilabel"],
min_sensitivity: float,
thresholds: Optional[Union[int, List[float], Tensor]] = None,
Expand Down
Loading
Loading