Skip to content

Commit

Permalink
🔖 version 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 26, 2024
1 parent bd5a9a5 commit b2e5dba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
## 简单实例

```python
from nepattern import BasePattern
from nepattern import Pattern


pat = BasePattern.of(int)
assert pat.validate(13).success
assert not 13.0 >> pat
pat = Pattern(str).accept(int).convert(lambda _, x: str(x))
assert pat.execute(13).success
assert pat.execute(42).value() == '42'
assert not pat << 13.0
```

## 特点
Expand Down
2 changes: 1 addition & 1 deletion nepattern/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __repr__(self):
def copy(self) -> Self:
return deepcopy(self)

def __rrshift__(self, other): # pragma: no cover
def __lshift__(self, other): # pragma: no cover
return self.execute(other)

def __rmatmul__(self, other) -> Self: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion nepattern/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _generic_parser(item: GenericAlias, extra: str) -> Pattern: # type: ignore
if origin in _Contents:
_args = {parser(t, extra) for t in get_args(item)}
return (_args.pop() if len(_args) == 1 else UnionPattern(*_args)) if _args else ANY
if origin in (list, tuple, set, dict):
if origin in (list, tuple, set, dict, type, frozenset):
item = origin[get_args(item)]
return Pattern(origin=item, alias=f"{repr(item).split('.')[-1]}").accept(item)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nepattern"
version = "0.7.6"
version = "0.8.0"
description = "a complex pattern, support typing"
authors = [
{name = "RF-Tar-Railt", email = "[email protected]"},
Expand Down
8 changes: 6 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_pattern_post_validator():


def test_parser():
from typing import Literal, Protocol, Type, TypeVar
from typing import Literal, Protocol, Type, TypeVar, Sequence
from typing_extensions import Annotated

pat11 = parser(int)
Expand All @@ -247,7 +247,7 @@ def test_parser():
pat11_2 = parser(int)
assert pat11_2 == pat11
assert isinstance(parser(Literal["a", "b"]), UnionPattern)
assert parser(Type[int]).origin is type
assert parser(Type[int]).origin == type[int]
assert parser(complex) != Pattern(complex)
assert isinstance(parser("a|b|c"), UnionPattern)
assert isinstance(parser("re:a|b|c"), Pattern)
Expand Down Expand Up @@ -288,6 +288,10 @@ def __setitem__(self): ...
assert pat11_7.execute("abc").success
assert pat11_7.execute([]).failed

pat11_8 = parser(Sequence[int])
assert pat11_8.execute([1, 2, 3]).success
assert pat11_8.execute((1, 2, 3)).success


def test_union_pattern():
from typing import List, Optional, Union, Annotated
Expand Down

0 comments on commit b2e5dba

Please sign in to comment.