-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overload signature of
get
to return an Optional value and to allow …
…default to take any type to match runtime behavior. This chage more closely matches the behavior of `get` at runtime. Users can pass whatever they want in to the default parameter and it will be returned if the key is absent. Additionally, `get` should return an `Optional` if called with only one parameter. ```python z = {'a': 22} reveal_type(z.get('b')) reveal_type(z.get('b', 22)) reveal_type(z.get('b', 'hello')) ``` Before: ```shell test_get_default.py:2: error: Revealed type is 'builtins.int*' test_get_default.py:3: error: Revealed type is 'builtins.int*' test_get_default.py:4: error: Revealed type is 'builtins.int*' test_get_default.py:4: error: Argument 2 to "get" of "dict" has incompatible type "str"; expected "int" ``` After: ```shell test_get_default.py:2: error: Revealed type is 'Union[builtins.int*, builtins.None]' test_get_default.py:3: error: Revealed type is 'builtins.int' test_get_default.py:4: error: Revealed type is 'Union[builtins.int, builtins.str*]' ```
- Loading branch information
Roy Williams
committed
Jan 12, 2017
1 parent
05c6c66
commit ccdd564
Showing
4 changed files
with
17 additions
and
7 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
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