Skip to content

Commit

Permalink
Fixed get overloads
Browse files Browse the repository at this point in the history
Moved default None above tag variant.
None matches the tag variant causing the wrong type hint.
Added more get overloads
  • Loading branch information
gentlegiantJGC committed Feb 27, 2024
1 parent f8c0e06 commit 449bf30
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 120 deletions.
74 changes: 36 additions & 38 deletions src/amulet_nbt/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -402,25 +402,7 @@ class CompoundTag(AbstractBaseMutableTag, MutableMapping[str | bytes, AnyNBT]):
"""A shallow copy of the CompoundTag as a python dictionary."""

@overload
def get(
self,
key: str | bytes,
default: _TagT = None,
cls: Type[_TagT] = AbstractBaseTag,
) -> _TagT: ...
@overload
def get(
self,
key: str | bytes,
default: None = None,
cls: Type[_TagT] = AbstractBaseTag,
) -> None: ...
def get(
self,
key: str | bytes,
default: _TagT | None = None,
cls: Type[_TagT] = AbstractBaseTag,
) -> _TagT | None:
def get(self, key: str | bytes, default: None = None) -> AnyNBT | None:
"""Get an item from the CompoundTag.
:param key: The key to get
Expand All @@ -431,76 +413,92 @@ class CompoundTag(AbstractBaseMutableTag, MutableMapping[str | bytes, AnyNBT]):
:raises: TypeError if the stored type is not a subclass of cls.
"""

@overload
def get(self, key: str | bytes, default: _TagT = None) -> AnyNBT: ...
@overload
def get(
self,
key: str | bytes,
default: None = None,
cls: Type[_TagT] = AbstractBaseTag,
) -> _TagT | None: ...
@overload
def get(
self,
key: str | bytes,
default: _TagT = None,
cls: Type[_TagT] = AbstractBaseTag,
) -> _TagT: ...
@staticmethod
def fromkeys(keys: Iterable[str | bytes], value: AnyNBT = None): ...
@overload
def get_byte(self, key: str | bytes, default: ByteTag = None) -> ByteTag: ...
@overload
def get_byte(self, key: str | bytes, default: None = None) -> ByteTag | None: ...
@overload
def get_short(self, key: str | bytes, default: ShortTag = None) -> ShortTag: ...
def get_byte(self, key: str | bytes, default: ByteTag = None) -> ByteTag: ...
@overload
def get_short(self, key: str | bytes, default: None = None) -> ShortTag | None: ...
@overload
def get_int(self, key: str | bytes, default: IntTag = None) -> IntTag: ...
def get_short(self, key: str | bytes, default: ShortTag = None) -> ShortTag: ...
@overload
def get_int(self, key: str | bytes, default: None = None) -> IntTag | None: ...
@overload
def get_long(self, key: str | bytes, default: LongTag = None) -> LongTag: ...
def get_int(self, key: str | bytes, default: IntTag = None) -> IntTag: ...
@overload
def get_long(self, key: str | bytes, default: None = None) -> LongTag | None: ...
@overload
def get_float(self, key: str | bytes, default: FloatTag = None) -> FloatTag: ...
def get_long(self, key: str | bytes, default: LongTag = None) -> LongTag: ...
@overload
def get_float(self, key: str | bytes, default: None = None) -> FloatTag | None: ...
@overload
def get_double(self, key: str | bytes, default: DoubleTag = None) -> DoubleTag: ...
def get_float(self, key: str | bytes, default: FloatTag = None) -> FloatTag: ...
@overload
def get_double(
self, key: str | bytes, default: None = None
) -> DoubleTag | None: ...
@overload
def get_string(self, key: str | bytes, default: StringTag = None) -> StringTag: ...
def get_double(self, key: str | bytes, default: DoubleTag = None) -> DoubleTag: ...
@overload
def get_string(
self, key: str | bytes, default: None = None
) -> StringTag | None: ...
@overload
def get_list(self, key: str | bytes, default: ListTag = None) -> ListTag: ...
def get_string(self, key: str | bytes, default: StringTag = None) -> StringTag: ...
@overload
def get_list(self, key: str | bytes, default: None = None) -> ListTag | None: ...
@overload
def get_list(self, key: str | bytes, default: ListTag = None) -> ListTag: ...
@overload
def get_compound(
self, key: str | bytes, default: None = None
) -> CompoundTag | None: ...
@overload
def get_compound(
self, key: str | bytes, default: CompoundTag = None
) -> CompoundTag: ...
@overload
def get_compound(
def get_byte_array(
self, key: str | bytes, default: None = None
) -> CompoundTag | None: ...
) -> ByteArrayTag | None: ...
@overload
def get_byte_array(
self, key: str | bytes, default: ByteArrayTag = None
) -> ByteArrayTag: ...
@overload
def get_byte_array(
def get_int_array(
self, key: str | bytes, default: None = None
) -> ByteArrayTag | None: ...
) -> IntArrayTag | None: ...
@overload
def get_int_array(
self, key: str | bytes, default: IntArrayTag = None
) -> IntArrayTag: ...
@overload
def get_int_array(
def get_long_array(
self, key: str | bytes, default: None = None
) -> IntArrayTag | None: ...
) -> LongArrayTag | None: ...
@overload
def get_long_array(
self, key: str | bytes, default: LongArrayTag = None
) -> LongArrayTag: ...
@overload
def get_long_array(
self, key: str | bytes, default: None = None
) -> LongArrayTag | None: ...
def setdefault_byte(
self, key: str | bytes, default: ByteTag | None = None
) -> ByteTag: ...
Expand Down
Loading

0 comments on commit 449bf30

Please sign in to comment.