Skip to content

Commit

Permalink
litte adjustments to typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco-Sulla committed Apr 29, 2023
1 parent ed3c132 commit 5905927
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 41 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ recursive-include src/frozendict/c_src *
include test/*
include src/frozendict/py.typed
include src/frozendict/__init__.pyi
include pyproject.toml
4 changes: 2 additions & 2 deletions src/frozendict/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TypeVar, overload, Type, Optional
from typing import TypeVar, overload, Type, Optional, Generic

try:
from typing import Mapping, Sequence, Iterable, Iterator, Tuple
Expand All @@ -14,7 +14,7 @@ SelfT = TypeVar("SelfT", bound=frozendict[K, V])

class frozendict(Mapping[K, V]):
@overload
def __new__(cls: Type[SelfT], **kwargs: V) -> SelfT: ...
def __new__(cls: Type[SelfT], **kwargs: V) -> frozendict[str, V]: ...
@overload
def __new__(cls: Type[SelfT], mapping: Mapping[K, V]) -> SelfT: ...
@overload
Expand Down
40 changes: 1 addition & 39 deletions test/typed.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,37 @@
from frozendict import frozendict
import copy

class FrozendictSubclass(frozendict):
def __new__(cls, *args, **kwargs):
return super().__new__(cls, *args, **kwargs)

d = dict(a=1, b=2)
fd = frozendict(a=1, b=2)
sub = FrozendictSubclass({"a": 1, "b": 2})
reveal_type(d["a"])
reveal_type(fd["a"])
reveal_type(sub["a"])
reveal_type(len(d))
reveal_type(len(fd))
reveal_type(len(sub))
reveal_type(iter(d))
reveal_type(iter(fd))
reveal_type(iter(sub))
reveal_type(hash(d))
reveal_type(hash(fd))
reveal_type(hash(sub))
reveal_type(repr(d))
reveal_type(repr(fd))
reveal_type(repr(sub))
reveal_type(dict.fromkeys("abc", 0))
reveal_type(frozendict.fromkeys("abc", 0))
reveal_type(FrozendictSubclass.fromkeys("abc", 0))
reveal_type(d.copy())
reveal_type(fd.copy())
reveal_type(sub.copy())
reveal_type(tuple(d.items())[0])
reveal_type(fd.item(0))
reveal_type(sub.item(0))
reveal_type(tuple(d.keys())[0])
reveal_type(fd.key(0))
reveal_type(sub.key(0))
reveal_type(tuple(d.values())[0])
reveal_type(fd.value(0))
reveal_type(sub.value(0))
reveal_type(d.get("a"))
reveal_type(fd.get("a"))
reveal_type(sub.get("a"))
reveal_type(d.items())
reveal_type(fd.items())
reveal_type(sub.items())
reveal_type(d.keys())
reveal_type(fd.keys())
reveal_type(sub.keys())
reveal_type(d.values())
reveal_type(fd.values())
reveal_type(sub.values())
reveal_type(copy.copy(d))
reveal_type(copy.copy(fd))
reveal_type(copy.copy(sub))
reveal_type(copy.deepcopy(d))
reveal_type(copy.deepcopy(fd))
reveal_type(copy.deepcopy(sub))
reveal_type(reversed(d))

reveal_type(reversed(fd))
reveal_type(reversed(sub))
reveal_type(d | {1: 2})
reveal_type(fd | {1: 2})
fd2 = frozendict({"a": 1, "b": 2})
reveal_type(fd2 | {1: 2})
reveal_type(sub | {1: 2})

reveal_type(fd.setdefault("a", 0))
reveal_type(sub.setdefault("a", 0))
reveal_type(fd.set("abc", 1))
reveal_type(sub.set("abc", 1))
reveal_type(fd.delete("a"))
reveal_type(sub.delete("a"))


0 comments on commit 5905927

Please sign in to comment.