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

Fix type hints #67

Merged
merged 4 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ platforms = any
[options]
package_dir=
=src
packages = find:
packages = find_namespace:
zip_safe = False
python_requires = ~=3.11
install_requires =
Expand Down
13 changes: 8 additions & 5 deletions src/amulet_nbt/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class StringTag(AbstractBaseImmutableTag):
def __lt__(self, other: Any) -> bool:
"""Check if the tag is less than another tag."""

AnyNBTT = TypeVar("AnyNBTT", bound=AnyNBT)
AnyNBTT = TypeVar("AnyNBTT", bound=AbstractBaseTag)

class ListTag(AbstractBaseMutableTag, MutableSequence[AnyNBTT]):
@overload
Expand Down Expand Up @@ -398,7 +398,7 @@ class ListTag(AbstractBaseMutableTag, MutableSequence[AnyNBTT]):
@overload
def __setitem__(self, index: int, value: AnyNBT) -> None: ...
@overload
def __setitem__(self, index: slice, value: Iterable[AnyNBT]) -> None: ...
def __setitem__(self, index: slice, value: Iterable[AbstractBaseTag]) -> None: ...
@overload
def __delitem__(self, index: int) -> None: ...
@overload
Expand All @@ -408,11 +408,14 @@ class ListTag(AbstractBaseMutableTag, MutableSequence[AnyNBTT]):

_TagT = TypeVar("_TagT", bound=AbstractBaseTag)

class CompoundTag(AbstractBaseMutableTag, MutableMapping[str | bytes, AnyNBT]):
class CompoundTag(AbstractBaseMutableTag, MutableMapping[str | bytes, AbstractBaseTag]):
def __init__(
self,
value: Mapping[str | bytes, AnyNBT] | Iterable[tuple[str | bytes, AnyNBT]] = (),
**kwvals: AnyNBT,
value: (
Mapping[str | bytes, AbstractBaseTag]
| Iterable[tuple[str | bytes, AbstractBaseTag]]
) = (),
**kwvals: AbstractBaseTag,
): ...
@property
def py_dict(self) -> dict[str, AnyNBT]:
Expand Down
2 changes: 1 addition & 1 deletion src/amulet_nbt/__init__.py → src/amulet_nbt/__init__.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

from ._errors import NBTError, NBTLoadError, NBTFormatError, SNBTParseError

from ._string_encoding import (
from ._string_encoding.encoding import (
mutf8_encoding,
utf8_encoding,
utf8_escape_encoding,
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions src/amulet_nbt/_string_encoding/__init__.py

This file was deleted.

8 changes: 8 additions & 0 deletions src/amulet_nbt/_string_encoding/__init__.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# distutils: language = c++
# distutils: extra_compile_args = CPPCARGS

from amulet_nbt._string_encoding.encoding import (
mutf8_encoding,
utf8_encoding,
utf8_escape_encoding
)
File renamed without changes.
16 changes: 8 additions & 8 deletions src/amulet_nbt/_tag/compound.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ cdef AbstractBaseTag wrap_node(TagNode* node):
raise RuntimeError


TagT = TypeVar("TagT", bound=AbstractBaseTag)
_TagT = TypeVar("_TagT", bound=AbstractBaseTag)


cdef class CompoundTag(AbstractBaseMutableTag):
Expand All @@ -222,8 +222,8 @@ cdef class CompoundTag(AbstractBaseMutableTag):

def __init__(
self,
value: Mapping[str | bytes, amulet_nbt.AnyNBT] | Iterable[tuple[str | bytes, amulet_nbt.AnyNBT]] = (),
**kwargs: amulet_nbt.AnyNBT,
value: Mapping[str | bytes, AbstractBaseTag] | Iterable[tuple[str | bytes, AbstractBaseTag]] = (),
**kwargs: AbstractBaseTag,
) -> None:
self.cpp = make_shared[CCompoundTag]()
self.update(value, **kwargs)
Expand Down Expand Up @@ -315,9 +315,9 @@ cdef class CompoundTag(AbstractBaseMutableTag):
return wrap_node(&dereference(it).second)

@overload
def get(self, key: str | bytes, default: None = None) -> AnyNBT | None:...
def get(self, key: str | bytes, default: None = None) -> amulet_nbt.AnyNBT | None:...
@overload
def get(self, key: str | bytes, default: _TagT = None) -> AnyNBT: ...
def get(self, key: str | bytes, default: _TagT = None) -> amulet_nbt.AnyNBT: ...
@overload
def get(self, key: str | bytes, default: None = None, cls: Type[_TagT] = AbstractBaseTag) -> _TagT | None: ...
@overload
Expand All @@ -326,9 +326,9 @@ cdef class CompoundTag(AbstractBaseMutableTag):
def get(
self,
string key: str | bytes,
object default: TagT | None = None,
object cls: Type[TagT] = AbstractBaseTag
) -> TagT | None:
object default: _TagT | None = None,
object cls: Type[_TagT] = AbstractBaseTag
) -> _TagT | None:
"""Get an item from the CompoundTag.

:param key: The key to get
Expand Down
16 changes: 8 additions & 8 deletions src/amulet_nbt/_tag/compound.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ f""" {"el"*(index!=1)}if index == {index}:
raise RuntimeError


TagT = TypeVar("TagT", bound=AbstractBaseTag)
_TagT = TypeVar("_TagT", bound=AbstractBaseTag)


cdef class CompoundTag(AbstractBaseMutableTag):
Expand All @@ -141,8 +141,8 @@ cdef class CompoundTag(AbstractBaseMutableTag):

def __init__(
self,
value: Mapping[str | bytes, amulet_nbt.AnyNBT] | Iterable[tuple[str | bytes, amulet_nbt.AnyNBT]] = (),
**kwargs: amulet_nbt.AnyNBT,
value: Mapping[str | bytes, AbstractBaseTag] | Iterable[tuple[str | bytes, AbstractBaseTag]] = (),
**kwargs: AbstractBaseTag,
) -> None:
self.cpp = make_shared[CCompoundTag]()
self.update(value, **kwargs)
Expand Down Expand Up @@ -221,9 +221,9 @@ cdef class CompoundTag(AbstractBaseMutableTag):
return wrap_node(&dereference(it).second)

@overload
def get(self, key: str | bytes, default: None = None) -> AnyNBT | None:...
def get(self, key: str | bytes, default: None = None) -> amulet_nbt.AnyNBT | None:...
@overload
def get(self, key: str | bytes, default: _TagT = None) -> AnyNBT: ...
def get(self, key: str | bytes, default: _TagT = None) -> amulet_nbt.AnyNBT: ...
@overload
def get(self, key: str | bytes, default: None = None, cls: Type[_TagT] = AbstractBaseTag) -> _TagT | None: ...
@overload
Expand All @@ -232,9 +232,9 @@ cdef class CompoundTag(AbstractBaseMutableTag):
def get(
self,
string key: str | bytes,
object default: TagT | None = None,
object cls: Type[TagT] = AbstractBaseTag
) -> TagT | None:
object default: _TagT | None = None,
object cls: Type[_TagT] = AbstractBaseTag
) -> _TagT | None:
"""Get an item from the CompoundTag.

:param key: The key to get
Expand Down
2 changes: 1 addition & 1 deletion src/amulet_nbt/_tag/list.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ cdef class ListTag(AbstractBaseMutableTag):
"""
tag_id: int = 9

def __init__(self, object value: Iterable[amulet_nbt.AnyNBT] = (), char element_tag_id = 1) -> None:
def __init__(self, object value: Iterable[AbstractBaseTag] = (), char element_tag_id = 1) -> None:
self.cpp = make_shared[CListTag]()
if element_tag_id == 0:
dereference(self.cpp).emplace[monostate]()
Expand Down
2 changes: 1 addition & 1 deletion src/amulet_nbt/_tag/list.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ cdef class ListTag(AbstractBaseMutableTag):
"""
tag_id: int = 9

def __init__(self, object value: Iterable[amulet_nbt.AnyNBT] = (), char element_tag_id = 1) -> None:
def __init__(self, object value: Iterable[AbstractBaseTag] = (), char element_tag_id = 1) -> None:
self.cpp = make_shared[CListTag]()
if element_tag_id == 0:
dereference(self.cpp).emplace[monostate]()
Expand Down
Loading