Skip to content

Commit

Permalink
fix: propagate generator type and forgot return annotation for hash()
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Apr 17, 2021
1 parent 9786c36 commit b1b1766
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions beet/toolchain/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from collections import defaultdict
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, DefaultDict, Optional, Tuple, overload
from typing import TYPE_CHECKING, Any, DefaultDict, Optional, Tuple, TypeVar, overload

from beet.library.base import NamespaceFile

Expand All @@ -15,6 +15,9 @@
from .context import Context


GeneratorType = TypeVar("GeneratorType", bound="Generator")


@dataclass
class Generator:
"""Helper for generating assets and data pack resources."""
Expand All @@ -25,8 +28,8 @@ class Generator:
default_factory=lambda: defaultdict(int) # type: ignore
)

def __getitem__(self, key: Any) -> "Generator":
return Generator(
def __getitem__(self: GeneratorType, key: Any) -> GeneratorType:
return self.__class__(
ctx=self.ctx,
scope=self.scope + (key,),
registry=self.registry,
Expand Down Expand Up @@ -118,7 +121,7 @@ def hash(
fmt: str,
hash: Optional[StableHashable] = None,
short: bool = False,
):
) -> str:
"""Generate a scoped hash."""
template = self.ctx.meta.get("generate_hash", "{namespace}.{scope}")
return stable_hash(self.format(template + fmt, hash), short)

0 comments on commit b1b1766

Please sign in to comment.