From 553f5910d8a51668ed971a4251293f588f2096c5 Mon Sep 17 00:00:00 2001 From: edayot Date: Fri, 12 Jul 2024 22:51:19 +0200 Subject: [PATCH] pyright passing --- beet/contrib/auto_yaml.py | 4 +-- beet/contrib/messages.py | 6 ++--- beet/contrib/rename_files.py | 2 +- beet/contrib/unknown_files.py | 8 +++--- beet/contrib/worldgen.py | 46 +++++++++++++++++------------------ beet/library/base.py | 2 +- beet/toolchain/query.py | 8 +++--- examples/load_extend/demo.py | 8 +++--- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/beet/contrib/auto_yaml.py b/beet/contrib/auto_yaml.py index 7da9fcc6..81f68337 100644 --- a/beet/contrib/auto_yaml.py +++ b/beet/contrib/auto_yaml.py @@ -10,7 +10,7 @@ from typing import Any, ClassVar, Tuple, Type -from beet import Context, Drop, JsonFileBase, NamespaceFile, Pack, YamlFile +from beet import Context, Drop, JsonFileBase, NamespaceFile, Pack, YamlFile, NamespaceFileScope def beet_default(ctx: Context): @@ -54,7 +54,7 @@ def create_namespace_handler( """Create handler that turns yaml namespace files into json.""" class AutoYamlNamespaceHandler(YamlFile): - scope: ClassVar[Tuple[str, ...]] = namespace_scope + scope: ClassVar[NamespaceFileScope] = namespace_scope extension: ClassVar[str] = namespace_extension model = file_type.model diff --git a/beet/contrib/messages.py b/beet/contrib/messages.py index 57aa7dff..62614d87 100644 --- a/beet/contrib/messages.py +++ b/beet/contrib/messages.py @@ -9,9 +9,9 @@ import json import re from dataclasses import dataclass -from typing import Any, ClassVar, Optional, Tuple, cast +from typing import Any, ClassVar, Optional, cast -from beet import Context, JsonFile +from beet import Context, JsonFile, NamespaceFileScope from beet.core.utils import TextComponent PATH_REGEX = re.compile(r"\w+") @@ -20,7 +20,7 @@ class Message(JsonFile): """Class representing a message file.""" - scope: ClassVar[Tuple[str, ...]] = ("messages",) + scope: ClassVar[NamespaceFileScope] = ("messages",) extension: ClassVar[str] = ".json" diff --git a/beet/contrib/rename_files.py b/beet/contrib/rename_files.py index 29ec1c8e..bc137b8a 100644 --- a/beet/contrib/rename_files.py +++ b/beet/contrib/rename_files.py @@ -12,7 +12,7 @@ import logging from dataclasses import dataclass -from typing import Any, Callable, List, Optional, Tuple, Type, Union, cast +from typing import Any, Callable, List, Optional, Type, Union, cast from pydantic.v1 import BaseModel diff --git a/beet/contrib/unknown_files.py b/beet/contrib/unknown_files.py index 95ce71fa..3ac876af 100644 --- a/beet/contrib/unknown_files.py +++ b/beet/contrib/unknown_files.py @@ -7,22 +7,22 @@ ] -from typing import ClassVar, Tuple +from typing import ClassVar -from beet import BinaryFile, Context +from beet import BinaryFile, Context, NamespaceFileScope class UnknownAsset(BinaryFile): """Class representing an unknown file in resource packs.""" - scope: ClassVar[Tuple[str, ...]] = () + scope: ClassVar[NamespaceFileScope] = () extension: ClassVar[str] = "" class UnknownData(BinaryFile): """Class representing an unknown file in data packs.""" - scope: ClassVar[Tuple[str, ...]] = () + scope: ClassVar[NamespaceFileScope] = () extension: ClassVar[str] = "" diff --git a/beet/contrib/worldgen.py b/beet/contrib/worldgen.py index 4bc4199a..f69cd00c 100644 --- a/beet/contrib/worldgen.py +++ b/beet/contrib/worldgen.py @@ -26,9 +26,9 @@ ] -from typing import ClassVar, Tuple, Union +from typing import ClassVar, Union -from beet import Context, DataPack, JsonFile, TagFile +from beet import Context, DataPack, JsonFile, TagFile, NamespaceFileScope def beet_default(ctx: Context): @@ -67,140 +67,140 @@ def worldgen(pack: Union[Context, DataPack]): class Dimension(JsonFile): """Class representing a dimension.""" - scope: ClassVar[Tuple[str, ...]] = ("dimension",) + scope: ClassVar[NamespaceFileScope] = ("dimension",) extension: ClassVar[str] = ".json" class DimensionType(JsonFile): """Class representing a dimension type.""" - scope: ClassVar[Tuple[str, ...]] = ("dimension_type",) + scope: ClassVar[NamespaceFileScope] = ("dimension_type",) extension: ClassVar[str] = ".json" class WorldgenBiome(JsonFile): """Class representing a biome.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "biome") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "biome") extension: ClassVar[str] = ".json" class WorldgenConfiguredCarver(JsonFile): """Class representing a worldgen carver.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "configured_carver") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "configured_carver") extension: ClassVar[str] = ".json" class WorldgenConfiguredFeature(JsonFile): """Class representing a worldgen feature.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "configured_feature") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "configured_feature") extension: ClassVar[str] = ".json" class WorldgenDensityFunction(JsonFile): """Class representing a density function.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "density_function") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "density_function") extension: ClassVar[str] = ".json" class WorldgenNoise(JsonFile): """Class representing a worldgen noise.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "noise") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "noise") extension: ClassVar[str] = ".json" class WorldgenNoiseSettings(JsonFile): """Class representing worldgen noise settings.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "noise_settings") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "noise_settings") extension: ClassVar[str] = ".json" class WorldgenPlacedFeature(JsonFile): """Class representing a placed feature.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "placed_feature") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "placed_feature") extension: ClassVar[str] = ".json" class WorldgenProcessorList(JsonFile): """Class representing a worldgen processor list.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "processor_list") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "processor_list") extension: ClassVar[str] = ".json" class WorldgenStructure(JsonFile): """Class representing a worldgen structure feature.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "structure") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "structure") extension: ClassVar[str] = ".json" class WorldgenStructureSet(JsonFile): """Class representing a worldgen structure set.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "structure_set") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "structure_set") extension: ClassVar[str] = ".json" class WorldgenConfiguredSurfaceBuilder(JsonFile): """Class representing a worldgen surface builder.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "configured_surface_builder") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "configured_surface_builder") extension: ClassVar[str] = ".json" class WorldgenTemplatePool(JsonFile): """Class representing a worldgen template pool.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "template_pool") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "template_pool") extension: ClassVar[str] = ".json" class WorldgenWorldPreset(JsonFile): """Class representing a worldgen world preset.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "world_preset") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "world_preset") extension: ClassVar[str] = ".json" class WorldgenFlatLevelGeneratorPreset(JsonFile): """Class representing a worldgen flat level generator preset.""" - scope: ClassVar[Tuple[str, ...]] = ("worldgen", "flat_level_generator_preset") + scope: ClassVar[NamespaceFileScope] = ("worldgen", "flat_level_generator_preset") extension: ClassVar[str] = ".json" class WorldgenBiomeTag(TagFile): """Class representing a biome tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "worldgen", "biome") + scope: ClassVar[NamespaceFileScope] = ("tags", "worldgen", "biome") class WorldgenStructureTag(TagFile): """Class representing a worldgen structure feature tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "worldgen", "structure") + scope: ClassVar[NamespaceFileScope] = ("tags", "worldgen", "structure") class WorldgenStructureSetTag(TagFile): """Class representing a worldgen structure set tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "worldgen", "structure_set") + scope: ClassVar[NamespaceFileScope] = ("tags", "worldgen", "structure_set") class WorldgenConfiguredCarverTag(TagFile): """Class representing a worldgen carver tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "worldgen", "configured_carver") + scope: ClassVar[NamespaceFileScope] = ("tags", "worldgen", "configured_carver") class WorldgenPlacedFeatureTag(TagFile): """Class representing a worldgen placed feature tag.""" - scope: ClassVar[Tuple[str, ...]] = ("tags", "worldgen", "placed_feature") + scope: ClassVar[NamespaceFileScope] = ("tags", "worldgen", "placed_feature") diff --git a/beet/library/base.py b/beet/library/base.py index 447e03bc..cd1c15e3 100644 --- a/beet/library/base.py +++ b/beet/library/base.py @@ -1591,7 +1591,7 @@ def get_output_scope(scope: NamespaceFileScope, pack_format: int) -> Tuple[str, if isinstance(scope, tuple): return scope result: Tuple[str, ...] | None = None - result_format : int | None = None + result_format: int | None = None for key, value in scope.items(): if key <= pack_format and (result_format is None or key > result_format): result = value diff --git a/beet/toolchain/query.py b/beet/toolchain/query.py index 5df32742..858c826f 100644 --- a/beet/toolchain/query.py +++ b/beet/toolchain/query.py @@ -49,7 +49,7 @@ from pydantic.v1 import BaseModel, validator from beet.core.file import File -from beet.library.base import NamespaceFile, Pack, create_group_map +from beet.library.base import NamespaceFile, Pack, create_group_map, get_output_scope from .config import ListOption from .template import TemplateManager @@ -229,7 +229,8 @@ def analyze_base_paths( escaped = GitWildMatchPattern.escape(path) if path == escaped: - prefix = "/".join([directory, namespace, *file_type.scope]) + scope = get_output_scope(file_type.scope, pack.pack_format) + prefix = "/".join([directory, namespace, *scope]) base_paths.add(f"{overlay}{prefix}/{path}{file_type.extension}") continue @@ -239,7 +240,8 @@ def analyze_base_paths( break common.append(part) - prefix = "/".join([directory, namespace, *file_type.scope, *common]) + scope = get_output_scope(file_type.scope, pack.pack_format) + prefix = "/".join([directory, namespace, *scope, *common]) base_paths.add(f"{overlay}{prefix}") return sorted(base_paths) diff --git a/examples/load_extend/demo.py b/examples/load_extend/demo.py index 41be59f2..9ce8aaa7 100644 --- a/examples/load_extend/demo.py +++ b/examples/load_extend/demo.py @@ -1,12 +1,12 @@ -from typing import ClassVar, Tuple, cast +from typing import ClassVar, cast from pydantic.v1 import BaseModel -from beet import Context, FileDeserialize, JsonFile, JsonFileBase, TextFile, YamlFile +from beet import Context, FileDeserialize, JsonFile, JsonFileBase, TextFile, YamlFile, NamespaceFileScope class FunctionConfig(YamlFile): - scope: ClassVar[Tuple[str, ...]] = ("functions",) + scope: ClassVar[NamespaceFileScope] = ("functions",) extension: ClassVar[str] = ".yml" @@ -17,7 +17,7 @@ class BlueprintData(BaseModel): class Blueprint(JsonFileBase[BlueprintData]): model = BlueprintData - scope: ClassVar[Tuple[str, ...]] = ("blueprints",) + scope: ClassVar[NamespaceFileScope] = ("blueprints",) extension: ClassVar[str] = ".json" data: ClassVar[FileDeserialize[BlueprintData]] = FileDeserialize()