Skip to content

Commit

Permalink
Python 3.7 support for new typings
Browse files Browse the repository at this point in the history
  • Loading branch information
wisp3rwind committed Jun 23, 2023
1 parent 12d70c8 commit f98987c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions beets/dbcore/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@
"""

from abc import ABC
import sys
import typing
from typing import Any, cast, Generic, Protocol, TypeVar, Union
from typing import Any, cast, Generic, TYPE_CHECKING, TypeVar, Union
from .query import BooleanQuery, FieldQuery, NumericQuery, SubstringQuery
from beets.util import str2bool


# Abstract base.


class ModelType(Protocol):
"""Protocol that specifies the required constructor for model types, i.e.
a function that takes any argument and attempts to parse it to the given
type.
"""
def __init__(self, value: Any = None):
...
# FIXME: unconditionally define the Protocol once we drop Python 3.7
if TYPE_CHECKING and sys.version_info >= (3, 8):
class ModelType(typing.Protocol):
"""Protocol that specifies the required constructor for model types,
i.e. a function that takes any argument and attempts to parse it to the
given type.
"""
def __init__(self, value: Any = None):
...
else:
# No structural subtyping in Python < 3.8...
ModelType = Any


# Generic type variables, used for the value type T and null type N (if
Expand Down

0 comments on commit f98987c

Please sign in to comment.