Skip to content

Commit

Permalink
Bump mypy from 0.982 to 1.0.0 in /requirements (#1516)
Browse files Browse the repository at this point in the history
* Bump mypy from 0.982 to 1.0.0 in /requirements

Bumps [mypy](https://github.com/python/mypy) from 0.982 to 1.0.0.
- [Release notes](https://github.com/python/mypy/releases)
- [Commits](python/mypy@v0.982...v1.0.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* mypy: Fix PEP 484 issues
* mypy: Drop unused ignore comments
* mypy: Function "Callable[[], bool]" could always be true in boolean context  [truthy-function]
* Apply suggestions from code review
* ignore
* optional

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: stancld <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Jirka <[email protected]>
  • Loading branch information
5 people authored Feb 22, 2023
1 parent 2322414 commit 596cc4c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
3 changes: 2 additions & 1 deletion requirements/typing.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mypy==0.982
mypy==1.0.0

types-PyYAML
types-emoji
types-protobuf
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/functional/regression/mae.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def _mean_absolute_error_update(preds: Tensor, target: Tensor) -> Tuple[Tensor,
target: Ground truth tensor
"""
_check_same_shape(preds, target)
preds = preds if preds.is_floating_point else preds.float()
target = target if target.is_floating_point else target.float()
preds = preds if preds.is_floating_point else preds.float() # type: ignore[truthy-function] # todo
target = target if target.is_floating_point else target.float() # type: ignore[truthy-function] # todo
sum_abs_error = torch.sum(torch.abs(preds - target))
n_obs = target.numel()
return sum_abs_error, n_obs
Expand Down
4 changes: 2 additions & 2 deletions src/torchmetrics/functional/text/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_embeddings_and_idf_scale(
all_layers: bool = False,
idf: bool = False,
verbose: bool = False,
user_forward_fn: Callable[[Module, Dict[str, Tensor]], Tensor] = None,
user_forward_fn: Optional[Callable[[Module, Dict[str, Tensor]], Tensor]] = None,
) -> Tuple[Tensor, Tensor]:
"""Calculate sentence embeddings and the inverse-document-frequency scaling factor.
Expand Down Expand Up @@ -249,7 +249,7 @@ def bert_score(
all_layers: bool = False,
model: Optional[Module] = None,
user_tokenizer: Any = None,
user_forward_fn: Callable[[Module, Dict[str, Tensor]], Tensor] = None,
user_forward_fn: Optional[Callable[[Module, Dict[str, Tensor]], Tensor]] = None,
verbose: bool = False,
idf: bool = False,
device: Optional[Union[str, torch.device]] = None,
Expand Down
12 changes: 6 additions & 6 deletions src/torchmetrics/functional/text/rouge.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def find_union(lcs_tables: Sequence[Sequence[int]]) -> Sequence[int]:
def _normalize_and_tokenize_text(
text: str,
stemmer: Optional[Any] = None,
normalizer: Callable[[str], str] = None,
tokenizer: Callable[[str], Sequence[str]] = None,
normalizer: Optional[Callable[[str], str]] = None,
tokenizer: Optional[Callable[[str], Sequence[str]]] = None,
) -> Sequence[str]:
"""Rouge score should be calculated only over lowercased words and digits. Optionally, Porter stemmer can be
used to strip word suffixes to improve matching. The text normalization follows the implemantion from `Rouge
Expand Down Expand Up @@ -282,8 +282,8 @@ def _rouge_score_update(
rouge_keys_values: List[Union[int, str]],
accumulate: str,
stemmer: Optional[Any] = None,
normalizer: Callable[[str], str] = None,
tokenizer: Callable[[str], Sequence[str]] = None,
normalizer: Optional[Callable[[str], str]] = None,
tokenizer: Optional[Callable[[str], Sequence[str]]] = None,
) -> Dict[Union[int, str], List[Dict[str, Tensor]]]:
"""Update the rouge score with the current set of predicted and target sentences.
Expand Down Expand Up @@ -412,8 +412,8 @@ def rouge_score(
target: Union[str, Sequence[str], Sequence[Sequence[str]]],
accumulate: Literal["avg", "best"] = "best",
use_stemmer: bool = False,
normalizer: Callable[[str], str] = None,
tokenizer: Callable[[str], Sequence[str]] = None,
normalizer: Optional[Callable[[str], str]] = None,
tokenizer: Optional[Callable[[str], Sequence[str]]] = None,
rouge_keys: Union[str, Tuple[str, ...]] = ("rouge1", "rouge2", "rougeL", "rougeLsum"),
) -> Dict[str, Tensor]:
"""Calculate `Calculate Rouge Score`_ , used for automatic summarization.
Expand Down
2 changes: 1 addition & 1 deletion src/torchmetrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def persistent(self, mode: bool = False) -> None:

def state_dict( # type: ignore[override] # todo
self,
destination: Dict[str, Any] = None,
destination: Optional[Dict[str, Any]] = None,
prefix: str = "",
keep_vars: bool = False,
) -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion src/torchmetrics/text/bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __init__(
all_layers: bool = False,
model: Optional[Module] = None,
user_tokenizer: Optional[Any] = None,
user_forward_fn: Callable[[Module, Dict[str, Tensor]], Tensor] = None,
user_forward_fn: Optional[Callable[[Module, Dict[str, Tensor]], Tensor]] = None,
verbose: bool = False,
idf: bool = False,
device: Optional[Union[str, torch.device]] = None,
Expand Down
6 changes: 3 additions & 3 deletions src/torchmetrics/text/rouge.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, Dict, List, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union

from torch import Tensor
from typing_extensions import Literal
Expand Down Expand Up @@ -97,8 +97,8 @@ class ROUGEScore(Metric):
def __init__(
self,
use_stemmer: bool = False,
normalizer: Callable[[str], str] = None,
tokenizer: Callable[[str], Sequence[str]] = None,
normalizer: Optional[Callable[[str], str]] = None,
tokenizer: Optional[Callable[[str], Sequence[str]]] = None,
accumulate: Literal["avg", "best"] = "best",
rouge_keys: Union[str, Tuple[str, ...]] = ("rouge1", "rouge2", "rougeL", "rougeLsum"),
**kwargs: Any,
Expand Down

0 comments on commit 596cc4c

Please sign in to comment.