Skip to content

Commit

Permalink
Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
scravy committed Apr 24, 2021
1 parent a6dfd4a commit e920779
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apm/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import collections.abc as abc
from copy import copy
from dataclasses import is_dataclass
from itertools import chain
from typing import Optional, List, Dict, Union, Tuple, Callable, Mapping
from typing import Optional, List, Dict, Union, Tuple, Callable

from .generic import AutoEqHash, AutoRepr

Expand Down Expand Up @@ -136,7 +137,7 @@ def get_wildcard_matches(self) -> List:
return wildcard_matches


class MatchResult(Mapping):
class MatchResult(abc.Mapping):
def __init__(self, *, matches: bool, context: MatchContext, match_stack: List[Tuple]):
self._matches: bool = matches
self._context: MatchContext = context
Expand Down Expand Up @@ -221,7 +222,7 @@ def transform(pattern, f):
def rf(p):
return transform(p, f)

if is_dataclass(pattern):
if is_dataclass(pattern) and not isinstance(pattern, type):
pattern = Dataclass(type(pattern), pattern.__dict__)

if isinstance(pattern, Nested):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

import unittest
# noinspection PyProtectedMember
from dataclasses import dataclass

from apm import *


@dataclass
class Foo:
x: int


class UtilTests(unittest.TestCase):

def test_issue_2(self):
"""https:/scravy/awesome-pattern-matching/issues/2"""

result = match(Foo(1), Foo, 'this matches', 'no match unfortunately')
self.assertEqual('this matches', result)

0 comments on commit e920779

Please sign in to comment.