Skip to content

Commit 4c95b35

Browse files
authored
Merge pull request #307 from vthemelis/fix-pmap-typing
fix: typing of `pmap`
2 parents bea5785 + 308b0a1 commit 4c95b35

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

pyrsistent/__init__.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ T = TypeVar('T')
4343
KT = TypeVar('KT')
4444
VT = TypeVar('VT')
4545

46+
@overload
47+
def pmap(initial: Mapping[KT, VT] = {}, pre_size: int = 0) -> PMap[KT, VT]: ...
48+
@overload
49+
def pmap(initial: Iterable[Tuple[KT, VT]] = {}, pre_size: int = 0) -> PMap[KT, VT]: ...
4650
def pmap(initial: Union[Mapping[KT, VT], Iterable[Tuple[KT, VT]]] = {}, pre_size: int = 0) -> PMap[KT, VT]: ...
4751
def m(**kwargs: VT) -> PMap[str, VT]: ...
4852

tests/typing_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Check that the inferred types are as expected.
2+
3+
from typing_extensions import assert_type
4+
from pyrsistent import PMap, pmap
5+
6+
assert_type(pmap(dict[tuple[int, str], float]()), PMap[tuple[int, str], float])

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ commands = pytest
2525
deps =
2626
pytest
2727
hypothesis
28+
typing_extensions
2829

2930
# Specifying the following tests like this is very non-DRY but I have no better solution right now.
3031
[testenv:coverage-py38]

0 commit comments

Comments
 (0)