Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 282f12a

Browse files
authored
fix abstract type hint (#2753)
1 parent 90839d0 commit 282f12a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

allennlp/nn/initializers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import logging
2626
import re
2727
import math
28-
from typing import Callable, List, Tuple, Type, Iterable, Dict
28+
from typing import Callable, List, Tuple, Type, Dict
2929
import itertools
3030
from overrides import overrides
3131

@@ -314,7 +314,7 @@ def __call__(self, module: torch.nn.Module) -> None:
314314
logger.info(" %s", name)
315315

316316
@classmethod
317-
def from_params(cls, params: Iterable[Tuple[str, Params]] = ()) -> "InitializerApplicator": # type: ignore
317+
def from_params(cls, params: List[Tuple[str, Params]] = None) -> "InitializerApplicator":
318318
"""
319319
Converts a Params object into an InitializerApplicator. The json should
320320
be formatted as follows::
@@ -345,7 +345,7 @@ def from_params(cls, params: Iterable[Tuple[str, Params]] = ()) -> "InitializerA
345345
An InitializerApplicator containing the specified initializers.
346346
"""
347347
# pylint: disable=arguments-differ
348-
348+
params = params or []
349349
is_prevent = lambda item: item == "prevent" or item == {"type": "prevent"}
350350
prevent_regexes = [param[0] for param in params if is_prevent(param[1])]
351351
params = [param for param in params if param[1] if not is_prevent(param[1])]

allennlp/tests/nn/initializers_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def tearDown(self):
2626
def test_from_params_string(self):
2727
Initializer.from_params(params="eye")
2828

29+
def test_from_params_none(self):
30+
Initializer.from_params(params=None)
31+
2932
def test_regex_matches_are_initialized_correctly(self):
3033
class Net(torch.nn.Module):
3134
def __init__(self):

0 commit comments

Comments
 (0)