Commit 565233e4 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Move bound TypeVar out of PatternEnum

parent d982944f
Loading
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
#  Copyright 2021  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#  Copyright 2021-2022  Dominik Sekotill <dom.sekotill@kodo.org.uk>
#
#  This Source Code Form is subject to the terms of the Mozilla Public
#  License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -20,14 +20,17 @@ from typing import overload
import behave
import parse

T = TypeVar("T")

__all__ = [
	"PatternEnum",
	"register_pattern",
]


if TYPE_CHECKING:
	T = TypeVar("T")
	C = TypeVar("C", bound="PatternEnum")


	class PatternConverter(Protocol):

		__name__: str
@@ -79,9 +82,10 @@ class EnumMeta(enum.EnumMeta):

	MEMBER_FILTER = 'member_filter'

	if TYPE_CHECKING:
		T = TypeVar("T", bound="EnumMeta")

	def __new__(mtc: type[T], name: str, bases: tuple[type, ...], attr: dict[str, Any], **kwds: Any) -> T:
	def __new__(mtc: type[T], name: str, bases: tuple[type, ...], attr: enum._EnumDict, **kwds: Any) -> T:
		member_names: list[str] = attr._member_names  # type: ignore
		member_filter = attr.pop(mtc.MEMBER_FILTER, None)
		if member_filter:
@@ -107,9 +111,6 @@ class PatternEnum(enum.Enum, metaclass=EnumMeta):
	type.
	"""

	if TYPE_CHECKING:
		C = TypeVar("C", bound="PatternEnum")

	@classmethod
	def _missing_(cls: type[C], key: Any) -> C:
		return cls[key]