Skip to content

Commit

Permalink
pyright passing
Browse files Browse the repository at this point in the history
  • Loading branch information
edayot committed Jul 12, 2024
1 parent cf74e52 commit 553f591
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 41 deletions.
4 changes: 2 additions & 2 deletions beet/contrib/auto_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions beet/contrib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+")
Expand All @@ -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"


Expand Down
2 changes: 1 addition & 1 deletion beet/contrib/rename_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions beet/contrib/unknown_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ""


Expand Down
46 changes: 23 additions & 23 deletions beet/contrib/worldgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions beet/toolchain/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions examples/load_extend/demo.py
Original file line number Diff line number Diff line change
@@ -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"


Expand All @@ -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()
Expand Down

0 comments on commit 553f591

Please sign in to comment.