From 9fa1cb5effb0b7dad84098352b32b93d1211d218 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Thu, 15 Feb 2024 14:25:28 +0000 Subject: [PATCH] Added type hints --- src/amulet_nbt/_nbt_encoding/_string/read_snbt.pyx | 9 ++++++++- src/amulet_nbt/_string_encoding/encoding.pyx | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/amulet_nbt/_nbt_encoding/_string/read_snbt.pyx b/src/amulet_nbt/_nbt_encoding/_string/read_snbt.pyx index e0d8fbce..70f5ee78 100644 --- a/src/amulet_nbt/_nbt_encoding/_string/read_snbt.pyx +++ b/src/amulet_nbt/_nbt_encoding/_string/read_snbt.pyx @@ -1,5 +1,6 @@ import re +import amulet_nbt from amulet_nbt._errors import SNBTParseError from amulet_nbt._tag.abc cimport AbstractBaseTag from amulet_nbt._tag.int cimport ByteTag, ShortTag, IntTag, LongTag @@ -207,7 +208,13 @@ cdef tuple _parse_snbt_recursive(unicode snbt, int index=0): return data, index -cpdef AbstractBaseTag from_snbt(unicode snbt): +def from_snbt(unicode snbt: str) -> amulet_nbt.AbstractBaseTag: + """Parse Stringified NBT. + + :param snbt: The SNBT string to parse. + :return: The tag + :raises: SNBTParseError if the SNBT format is invalid. + """ try: return _parse_snbt_recursive(snbt)[0] except SNBTParseError as e: diff --git a/src/amulet_nbt/_string_encoding/encoding.pyx b/src/amulet_nbt/_string_encoding/encoding.pyx index 544e108f..36455a0b 100644 --- a/src/amulet_nbt/_string_encoding/encoding.pyx +++ b/src/amulet_nbt/_string_encoding/encoding.pyx @@ -11,10 +11,10 @@ from ._cpp.mutf8 cimport ( cdef class StringEncoding: - def encode(self, bytes data) -> bytes: + def encode(self, bytes data: bytes) -> bytes: return self.encode_cpp(data) - def decode(self, bytes data) -> bytes: + def decode(self, bytes data: bytes) -> bytes: return self.decode_cpp(data)