Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kszucs/koerce
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ab5537289371b44c0b854004f81d9eaca24f6110
Choose a base ref
..
head repository: kszucs/koerce
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8f6a9f8a0a98a23d515b2f187c5441177e095bbe
Choose a head ref
Showing with 28 additions and 28 deletions.
  1. +2 −2 koerce/builders.py
  2. +25 −25 koerce/patterns.py
  3. +1 −1 koerce/utils.py
4 changes: 2 additions & 2 deletions koerce/builders.py
Original file line number Diff line number Diff line change
@@ -664,7 +664,7 @@ class Sequence(Builder):
The items to construct the sequence from.
"""

type_: Any
type_: type
items: list[Builder]

def __init__(self, items):
@@ -703,7 +703,7 @@ class Mapping(Builder):
The items to construct the mapping from.
"""

type_: Any
type_: type
items: dict[Any, Builder]

def __init__(self, items):
50 changes: 25 additions & 25 deletions koerce/patterns.py
Original file line number Diff line number Diff line change
@@ -488,9 +488,9 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class InstanceOf(Pattern):
type_: Any
type_: type

def __init__(self, type_: Any):
def __init__(self, type_: type):
self.type_ = type_

def __repr__(self) -> str:
@@ -516,7 +516,7 @@ def match(self, value, ctx: Context):
class LazyInstanceOf(Pattern):
qualname: str
package: str
type_: Any
type_: type

def __init__(self, qualname: str):
_common_package_aliases: dict[str, str] = {
@@ -556,7 +556,7 @@ def match(self, value, ctx: Context):
else:
raise NoMatchError()

klass: Any
klass: type
package: str
for klass in type(value).__mro__:
package = klass.__module__.split(".", 1)[0]
@@ -585,7 +585,7 @@ def GenericInstanceOf(typ) -> Pattern:
@cython.final
@cython.cclass
class GenericInstanceOf1(Pattern):
origin: Any
origin: type
name1: str
pattern1: Pattern

@@ -622,7 +622,7 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class GenericInstanceOf2(Pattern):
origin: Any
origin: type
name1: str
name2: str
pattern1: Pattern
@@ -667,7 +667,7 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class GenericInstanceOfN(Pattern):
origin: Any
origin: type
fields: dict[str, Pattern]

def __init__(self, typ):
@@ -704,9 +704,9 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class SubclassOf(Pattern):
type_: Any
type_: type

def __init__(self, type_: Any):
def __init__(self, type_: type):
self.type_ = type_

def __repr__(self) -> str:
@@ -725,7 +725,7 @@ def match(self, value, ctx: Context):


# @cython.ccall
# def As(type_: Any) -> Pattern:
# def As(type_: type) -> Pattern:
# origin = get_type_origin(type_)
# if origin is None:
# if hasattr(type_, "__coerce__"):
@@ -742,9 +742,9 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class AsType(Pattern):
type_: Any
type_: type

def __init__(self, type_: Any):
def __init__(self, type_: type):
self.type_ = type_

def __repr__(self) -> str:
@@ -764,9 +764,9 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class CoercedTo(Pattern):
type_: Any
type_: type

def __init__(self, type_: Any):
def __init__(self, type_: type):
if not hasattr(type_, "__coerce__"):
raise TypeError(f"{type_} does not implement the Coercible protocol")
self.type_ = type_
@@ -796,7 +796,7 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class GenericCoercedTo(Pattern):
origin: Any
origin: type
params: dict[str, type]
checker: Pattern

@@ -1317,11 +1317,11 @@ def _reconstruct(value: Any, changed: dict[str, Any]):
@cython.final
@cython.cclass
class ObjectOf1(Pattern):
type_: Any
type_: type
field1: str
pattern1: Pattern

def __init__(self, type_: Any, **kwargs):
def __init__(self, type_: type, **kwargs):
assert len(kwargs) == 1
self.type_ = type_
((self.field1, pattern1),) = kwargs.items()
@@ -1355,13 +1355,13 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class ObjectOf2(Pattern):
type_: Any
type_: type
field1: str
pattern1: Pattern
field2: str
pattern2: Pattern

def __init__(self, type_: Any, **kwargs):
def __init__(self, type_: type, **kwargs):
assert len(kwargs) == 2
self.type_ = type_
(self.field1, pattern1), (self.field2, pattern2) = kwargs.items()
@@ -1401,15 +1401,15 @@ def match(self, value, ctx: Context):
@cython.final
@cython.cclass
class ObjectOf3(Pattern):
type_: Any
type_: type
field1: str
field2: str
field3: str
pattern1: Pattern
pattern2: Pattern
pattern3: Pattern

def __init__(self, type_: Any, **kwargs):
def __init__(self, type_: type, **kwargs):
assert len(kwargs) == 3
self.type_ = type_
(self.field1, pattern1), (self.field2, pattern2), (self.field3, pattern3) = (
@@ -1477,10 +1477,10 @@ class ObjectOfN(Pattern):
"""

type_: Any
type_: type
fields: dict[str, Pattern]

def __init__(self, type_: Any, **kwargs):
def __init__(self, type_: type, **kwargs):
self.type_ = type_
self.fields = {k: pattern(v) for k, v in kwargs.items()}

@@ -1769,7 +1769,7 @@ class FixedPatternList(Pattern):
"""

patterns: list[Pattern]
type_: Any
type_: type

def __init__(self, patterns, type):
self.patterns = list(map(pattern, patterns))
@@ -1811,7 +1811,7 @@ def match(self, values, ctx: Context):
@cython.cclass
class VariadicPatternList(Pattern):
patterns: list[Pattern]
type_: Any
type_: type

def __init__(self, patterns, type=list):
self.patterns = list(map(pattern, patterns))
2 changes: 1 addition & 1 deletion koerce/utils.py
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ def get_type_params(typ: Any) -> dict[TypeVar, type]:
{'T': <class 'int'>, 'U': <class 'str'>}
"""
args: tuple = get_type_args(typ)
origin: Any = get_type_origin(typ) # or typ
origin: type = get_type_origin(typ) # or typ
params: tuple = getattr(origin, "__parameters__", ())

result: dict[str, type] = {}