Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type annotations to pyi interface file. #70

Merged
merged 28 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f5f5627
Added type annotations to interface.
gauravmm Dec 20, 2022
7f9555c
Update frozendict.pyi
gauravmm Dec 20, 2022
bbdd123
removed typeshed
Marco-Sulla Dec 20, 2022
0a69ed3
Lazier TypeVar variable names
Marco-Sulla Dec 20, 2022
620997f
No more dict_cls
Marco-Sulla Dec 20, 2022
836baf0
removed blacklisted methods
Marco-Sulla Dec 20, 2022
658e91d
changed tuple with generic Sequence
Marco-Sulla Dec 20, 2022
d820cf9
key type must be hashable
Marco-Sulla Dec 20, 2022
6843d2f
typo
Marco-Sulla Dec 20, 2022
07d3d5a
fixed __reversed__ return type
Marco-Sulla Dec 20, 2022
915ce02
support python < 3.9
Marco-Sulla Dec 20, 2022
6a377cb
Fixed frozendict returns and self
Marco-Sulla Dec 20, 2022
273ce74
No __ior__ for an immutable
Marco-Sulla Dec 20, 2022
6aa1e27
minor
Marco-Sulla Dec 20, 2022
566f508
support subclassing
Marco-Sulla Dec 20, 2022
2df287f
added fromkeys
Marco-Sulla Dec 20, 2022
3d35a8e
removing Generic (not sure)
Marco-Sulla Dec 20, 2022
2ba8db7
removed frozendict_or
Marco-Sulla Dec 20, 2022
1d81d08
removed IMHO unnecessary underscores
Marco-Sulla Dec 20, 2022
4dc9462
Rename frozendict.pyi to __init__.pyi
Marco-Sulla Apr 26, 2023
2da7ed9
Update __init__.pyi
Marco-Sulla Apr 26, 2023
272b2a3
key can'b be Hashable....
Marco-Sulla Apr 26, 2023
ab94dda
renamed pyi
Marco-Sulla Apr 26, 2023
79788c7
renamed pyi
Marco-Sulla Apr 26, 2023
1380b1b
Merge branch 'master' into feature-typeannotations
Marco-Sulla Apr 26, 2023
d9e7792
Rename frozendict/__init__.pyi to src/frozendict/__init.py
Marco-Sulla Apr 26, 2023
31cae8b
Rename __init.py to __init__.pyi
Marco-Sulla Apr 26, 2023
5226d25
Delete frozendict.pyi
Marco-Sulla Apr 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
recursive-include src/frozendict/c_src *
include test/*
include src/frozendict/py.typed
include src/frozendict/frozendict.pyi
include src/frozendict/__init__.pyi
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
readme_filename = "README.md"
version_filename = "version.py"
py_typed_filename = "py.typed"
mypy_filename = "frozendict.pyi"
mypy_filename = "__init__.pyi"
main_url = "https://github.com/Marco-Sulla/python-frozendict"
bug_url = "https://github.com/Marco-Sulla/python-frozendict/issues"
author = "Marco Sulla"
Expand Down
54 changes: 54 additions & 0 deletions src/frozendict/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from collections.abc import Hashable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Hashable is imported but not actually used?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is highly possible.

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

try:
from typing import Mapping, Sequence, Iterable, Iterator
except ImportError:
from collections.abc import Mapping, Sequence, Iterable, Iterator

K = TypeVar("K")
V = TypeVar("V")
KV = TypeVar("KV", K, V)
T = TypeVar("T", Mapping[K, V])

class frozendict(Mapping[K, V]):
# Fake __init__ to describe what __new__ does:
@overload
def __init__(self, **kwargs: V) -> None: ...
@overload
def __init__(self, mapping: Mapping[K, V]) -> None: ...
@overload
def __init__(self, iterable: Iterable[Sequence[KV]]) -> None: ...

# Magic Methods:
def __getitem__(self, key: K) -> V: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[K]: ...
def __hash__(self) -> int: ...
def __repr__(self) -> str: ...
def copy(self: T) -> T: ...
def __copy__(self: T) -> T: ...
def __deepcopy__(self: T) -> T: ...
# Omit __reduce__, its used for Pickle and we don't need the annotation in code.
def set(self: T, key: K, value: V) -> T: ...
def setdefault(self: T, key: K, default: V) -> T: ...
def delete(self: T, key: K) -> T: ...
def key(self, index: int) -> K: ...
def value(self, index: int) -> V: ...
def item(self, index: int) -> Sequence[KV]: ...
def __or__(self: T, other: Mapping[K, V]) -> T: ...
def __reversed__(self) -> Iterator[K]: ...

@classmethod
def fromkeys(
cls: Type[T],
seq: Iterable[K],
value: Optional[V] = None
) -> "frozendict[K, V]": ...

# Blacklisted methods:
def __setattr__(self, *a, **kw) -> NoReturn: ...
def __delattr__(self, *a, **kw) -> NoReturn: ...


FrozenOrderedDict = frozendict
6 changes: 0 additions & 6 deletions src/frozendict/frozendict.pyi

This file was deleted.