Skip to content

Commit

Permalink
fix: annotate descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Feb 21, 2021
1 parent c74d4cb commit 4e47cc6
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 77 deletions.
10 changes: 5 additions & 5 deletions beet/core/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def __set__(self, obj: File[ValueType, Any], value: ValueType):
class TextFileBase(File[ValueType, str]):
"""Base class for files that get serialized to strings."""

text = FileSerialize[str]()
text: FileSerialize[str] = FileSerialize()

@classmethod
def serialize(cls, content: Union[ValueType, str]) -> str:
Expand Down Expand Up @@ -214,7 +214,7 @@ def from_str(cls, content: str) -> str:
class BinaryFileBase(File[ValueType, bytes]):
"""Base class for files that get serialized to bytes."""

blob = FileSerialize[bytes]()
blob: FileSerialize[bytes] = FileSerialize()

@classmethod
def serialize(cls, content: Union[ValueType, bytes]) -> bytes:
Expand Down Expand Up @@ -258,7 +258,7 @@ def from_bytes(cls, content: bytes) -> bytes:
class JsonFileBase(TextFileBase[ValueType]):
"""Base class for json files."""

data = FileDeserialize[ValueType]()
data: FileDeserialize[ValueType] = FileDeserialize()

@classmethod
def to_str(cls, content: ValueType) -> str:
Expand All @@ -272,13 +272,13 @@ def from_str(cls, content: str) -> ValueType:
class JsonFile(JsonFileBase[JsonDict]):
"""Class representing a json file."""

data = FileDeserialize[JsonDict]()
data: FileDeserialize[JsonDict] = FileDeserialize()


class PngFile(BinaryFileBase[img.Image]):
"""Class representing a png file."""

image = FileDeserialize[img.Image]()
image: FileDeserialize[img.Image] = FileDeserialize()

@classmethod
def to_bytes(cls, content: img.Image) -> bytes:
Expand Down
10 changes: 6 additions & 4 deletions beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ class Pack(MatchMixin, MergeMixin, Container[str, NamespaceType]):
zipped: bool

extra: PackContainer
mcmeta = PackPin[JsonFile]("pack.mcmeta", default_factory=lambda: JsonFile({}))
image = PackPin[Optional[PngFile]]("pack.png", default=None)
mcmeta: PackPin[JsonFile] = PackPin(
"pack.mcmeta", default_factory=lambda: JsonFile({})
)
image: PackPin[Optional[PngFile]] = PackPin("pack.png", default=None)

description = McmetaPin[TextComponent]("description", default="")
pack_format = McmetaPin[int]("pack_format", default=0)
description: McmetaPin[TextComponent] = McmetaPin("description", default="")
pack_format: McmetaPin[int] = McmetaPin("pack_format", default=0)

namespace_type: ClassVar[Type[NamespaceType]]
default_name: ClassVar[str]
Expand Down
88 changes: 44 additions & 44 deletions beet/library/data_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Function(TextFileBase[MutableSequence[str]], NamespaceFile):
scope = ("functions",)
extension = ".mcfunction"

lines = FileDeserialize[MutableSequence[str]]()
lines = FileDeserialize() # type: FileDeserialize[MutableSequence[str]]

@classmethod
def to_str(cls, content: MutableSequence[str]) -> str:
Expand Down Expand Up @@ -115,7 +115,7 @@ class Structure(BinaryFileBase[StructureFileData], NamespaceFile):
scope = ("structures",)
extension = ".nbt"

data = FileDeserialize[StructureFileData]()
data = FileDeserialize() # type: FileDeserialize[StructureFileData]

@classmethod
def from_bytes(cls, content: bytes) -> StructureFileData:
Expand Down Expand Up @@ -253,27 +253,27 @@ class DataPackNamespace(Namespace):
directory = "data"

# fmt: off
advancements = NamespacePin(Advancement)
functions = NamespacePin(Function)
loot_tables = NamespacePin(LootTable)
predicates = NamespacePin(Predicate)
recipes = NamespacePin(Recipe)
structures = NamespacePin(Structure)
block_tags = NamespacePin(BlockTag)
entity_type_tags = NamespacePin(EntityTypeTag)
fluid_tags = NamespacePin(FluidTag)
function_tags = NamespacePin(FunctionTag)
item_tags = NamespacePin(ItemTag)
dimension_types = NamespacePin(DimensionType)
dimensions = NamespacePin(Dimension)
biomes = NamespacePin(Biome)
configured_carvers = NamespacePin(ConfiguredCarver)
configured_features = NamespacePin(ConfiguredFeature)
configured_structure_features = NamespacePin(ConfiguredStructureFeature)
configured_surface_builders = NamespacePin(ConfiguredSurfaceBuilder)
noise_settings = NamespacePin(NoiseSettings)
processor_lists = NamespacePin(ProcessorList)
template_pools = NamespacePin(TemplatePool)
advancements: NamespacePin[Advancement] = NamespacePin(Advancement)
functions: NamespacePin[Function] = NamespacePin(Function)
loot_tables: NamespacePin[LootTable] = NamespacePin(LootTable)
predicates: NamespacePin[Predicate] = NamespacePin(Predicate)
recipes: NamespacePin[Recipe] = NamespacePin(Recipe)
structures: NamespacePin[Structure] = NamespacePin(Structure)
block_tags: NamespacePin[BlockTag] = NamespacePin(BlockTag)
entity_type_tags: NamespacePin[EntityTypeTag] = NamespacePin(EntityTypeTag)
fluid_tags: NamespacePin[FluidTag] = NamespacePin(FluidTag)
function_tags: NamespacePin[FunctionTag] = NamespacePin(FunctionTag)
item_tags: NamespacePin[ItemTag] = NamespacePin(ItemTag)
dimension_types: NamespacePin[DimensionType] = NamespacePin(DimensionType)
dimensions: NamespacePin[Dimension] = NamespacePin(Dimension)
biomes: NamespacePin[Biome] = NamespacePin(Biome)
configured_carvers: NamespacePin[ConfiguredCarver] = NamespacePin(ConfiguredCarver)
configured_features: NamespacePin[ConfiguredFeature] = NamespacePin(ConfiguredFeature)
configured_structure_features: NamespacePin[ConfiguredStructureFeature] = NamespacePin(ConfiguredStructureFeature)
configured_surface_builders: NamespacePin[ConfiguredSurfaceBuilder] = NamespacePin(ConfiguredSurfaceBuilder)
noise_settings: NamespacePin[NoiseSettings] = NamespacePin(NoiseSettings)
processor_lists: NamespacePin[ProcessorList] = NamespacePin(ProcessorList)
template_pools: NamespacePin[TemplatePool] = NamespacePin(TemplatePool)
# fmt: on


Expand All @@ -284,25 +284,25 @@ class DataPack(Pack[DataPackNamespace]):
latest_pack_format = 6

# fmt: off
advancements = NamespaceProxyDescriptor(Advancement)
functions = NamespaceProxyDescriptor(Function)
loot_tables = NamespaceProxyDescriptor(LootTable)
predicates = NamespaceProxyDescriptor(Predicate)
recipes = NamespaceProxyDescriptor(Recipe)
structures = NamespaceProxyDescriptor(Structure)
block_tags = NamespaceProxyDescriptor(BlockTag)
entity_type_tags = NamespaceProxyDescriptor(EntityTypeTag)
fluid_tags = NamespaceProxyDescriptor(FluidTag)
function_tags = NamespaceProxyDescriptor(FunctionTag)
item_tags = NamespaceProxyDescriptor(ItemTag)
dimension_types = NamespaceProxyDescriptor(DimensionType)
dimensions = NamespaceProxyDescriptor(Dimension)
biomes = NamespaceProxyDescriptor(Biome)
configured_carvers = NamespaceProxyDescriptor(ConfiguredCarver)
configured_features = NamespaceProxyDescriptor(ConfiguredFeature)
configured_structure_features = NamespaceProxyDescriptor(ConfiguredStructureFeature)
configured_surface_builders = NamespaceProxyDescriptor(ConfiguredSurfaceBuilder)
noise_settings = NamespaceProxyDescriptor(NoiseSettings)
processor_lists = NamespaceProxyDescriptor(ProcessorList)
template_pools = NamespaceProxyDescriptor(TemplatePool)
advancements: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement)
functions: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function)
loot_tables: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable)
predicates: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate)
recipes: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe)
structures: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure)
block_tags: NamespaceProxyDescriptor[BlockTag] = NamespaceProxyDescriptor(BlockTag)
entity_type_tags: NamespaceProxyDescriptor[EntityTypeTag] = NamespaceProxyDescriptor(EntityTypeTag)
fluid_tags: NamespaceProxyDescriptor[FluidTag] = NamespaceProxyDescriptor(FluidTag)
function_tags: NamespaceProxyDescriptor[FunctionTag] = NamespaceProxyDescriptor(FunctionTag)
item_tags: NamespaceProxyDescriptor[ItemTag] = NamespaceProxyDescriptor(ItemTag)
dimension_types: NamespaceProxyDescriptor[DimensionType] = NamespaceProxyDescriptor(DimensionType)
dimensions: NamespaceProxyDescriptor[Dimension] = NamespaceProxyDescriptor(Dimension)
biomes: NamespaceProxyDescriptor[Biome] = NamespaceProxyDescriptor(Biome)
configured_carvers: NamespaceProxyDescriptor[ConfiguredCarver] = NamespaceProxyDescriptor(ConfiguredCarver)
configured_features: NamespaceProxyDescriptor[ConfiguredFeature] = NamespaceProxyDescriptor(ConfiguredFeature)
configured_structure_features: NamespaceProxyDescriptor[ConfiguredStructureFeature] = NamespaceProxyDescriptor(ConfiguredStructureFeature)
configured_surface_builders: NamespaceProxyDescriptor[ConfiguredSurfaceBuilder] = NamespaceProxyDescriptor(ConfiguredSurfaceBuilder)
noise_settings: NamespaceProxyDescriptor[NoiseSettings] = NamespaceProxyDescriptor(NoiseSettings)
processor_lists: NamespaceProxyDescriptor[ProcessorList] = NamespaceProxyDescriptor(ProcessorList)
template_pools: NamespaceProxyDescriptor[TemplatePool] = NamespaceProxyDescriptor(TemplatePool)
# fmt: on
48 changes: 24 additions & 24 deletions beet/library/resource_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ class ResourcePackNamespace(Namespace):
directory = "assets"

# fmt: off
blockstates = NamespacePin(Blockstate)
models = NamespacePin(Model)
fonts = NamespacePin(Font)
glyph_sizes = NamespacePin(GlyphSizeFile)
truetype_fonts = NamespacePin(TrueTypeFont)
shader_posts = NamespacePin(ShaderPost)
shader_programs = NamespacePin(ShaderProgram)
fragment_shaders = NamespacePin(FragmentShader)
vertex_shaders = NamespacePin(VertexShader)
texts = NamespacePin(Text)
textures_mcmeta = NamespacePin(TextureMcmeta)
textures = NamespacePin(Texture)
blockstates: NamespacePin[Blockstate] = NamespacePin(Blockstate)
models: NamespacePin[Model] = NamespacePin(Model)
fonts: NamespacePin[Font] = NamespacePin(Font)
glyph_sizes: NamespacePin[GlyphSizeFile] = NamespacePin(GlyphSizeFile)
truetype_fonts: NamespacePin[TrueTypeFont] = NamespacePin(TrueTypeFont)
shader_posts: NamespacePin[ShaderPost] = NamespacePin(ShaderPost)
shader_programs: NamespacePin[ShaderProgram] = NamespacePin(ShaderProgram)
fragment_shaders: NamespacePin[FragmentShader] = NamespacePin(FragmentShader)
vertex_shaders: NamespacePin[VertexShader] = NamespacePin(VertexShader)
texts: NamespacePin[Text] = NamespacePin(Text)
textures_mcmeta: NamespacePin[TextureMcmeta] = NamespacePin(TextureMcmeta)
textures: NamespacePin[Texture] = NamespacePin(Texture)
# fmt: on


Expand All @@ -157,16 +157,16 @@ class ResourcePack(Pack[ResourcePackNamespace]):
latest_pack_format = 6

# fmt: off
blockstates = NamespaceProxyDescriptor(Blockstate)
models = NamespaceProxyDescriptor(Model)
fonts = NamespaceProxyDescriptor(Font)
glyph_sizes = NamespaceProxyDescriptor(GlyphSizeFile)
truetype_fonts = NamespaceProxyDescriptor(TrueTypeFont)
shader_posts = NamespaceProxyDescriptor(ShaderPost)
shader_programs = NamespaceProxyDescriptor(ShaderProgram)
fragment_shaders = NamespaceProxyDescriptor(FragmentShader)
vertex_shaders = NamespaceProxyDescriptor(VertexShader)
texts = NamespaceProxyDescriptor(Text)
textures_mcmeta = NamespaceProxyDescriptor(TextureMcmeta)
textures = NamespaceProxyDescriptor(Texture)
blockstates: NamespaceProxyDescriptor[Blockstate] = NamespaceProxyDescriptor(Blockstate)
models: NamespaceProxyDescriptor[Model] = NamespaceProxyDescriptor(Model)
fonts: NamespaceProxyDescriptor[Font] = NamespaceProxyDescriptor(Font)
glyph_sizes: NamespaceProxyDescriptor[GlyphSizeFile] = NamespaceProxyDescriptor(GlyphSizeFile)
truetype_fonts: NamespaceProxyDescriptor[TrueTypeFont] = NamespaceProxyDescriptor(TrueTypeFont)
shader_posts: NamespaceProxyDescriptor[ShaderPost] = NamespaceProxyDescriptor(ShaderPost)
shader_programs: NamespaceProxyDescriptor[ShaderProgram] = NamespaceProxyDescriptor(ShaderProgram)
fragment_shaders: NamespaceProxyDescriptor[FragmentShader] = NamespaceProxyDescriptor(FragmentShader)
vertex_shaders: NamespaceProxyDescriptor[VertexShader] = NamespaceProxyDescriptor(VertexShader)
texts: NamespaceProxyDescriptor[Text] = NamespaceProxyDescriptor(Text)
textures_mcmeta: NamespaceProxyDescriptor[TextureMcmeta] = NamespaceProxyDescriptor(TextureMcmeta)
textures: NamespaceProxyDescriptor[Texture] = NamespaceProxyDescriptor(Texture)
# fmt: on

0 comments on commit 4e47cc6

Please sign in to comment.