Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions boolean/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from . import boolean as boolean
from .boolean import AND as AND
from .boolean import NOT as NOT
from .boolean import OR as OR
from .boolean import PARSE_ERRORS as PARSE_ERRORS
from .boolean import TOKEN_AND as TOKEN_AND
from .boolean import TOKEN_FALSE as TOKEN_FALSE
from .boolean import TOKEN_LPAR as TOKEN_LPAR
from .boolean import TOKEN_NOT as TOKEN_NOT
from .boolean import TOKEN_OR as TOKEN_OR
from .boolean import TOKEN_RPAR as TOKEN_RPAR
from .boolean import TOKEN_SYMBOL as TOKEN_SYMBOL
from .boolean import TOKEN_TRUE as TOKEN_TRUE
from .boolean import BooleanAlgebra as BooleanAlgebra
from .boolean import Expression as Expression
from .boolean import ParseError as ParseError
from .boolean import Symbol as Symbol
231 changes: 231 additions & 0 deletions boolean/boolean.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import inspect as inspect
import itertools as itertools
from collections.abc import Callable, Container, Iterable, Iterator, Mapping
from functools import reduce as reduce
from operator import and_ as and_operator
from operator import or_ as or_operator
from typing import ClassVar, TypeVar

import boolean.boolean as _boolean

_ValueT = TypeVar("_ValueT")

TRACE_PARSE: bool

TOKEN_AND: int
TOKEN_OR: int
TOKEN_NOT: int
TOKEN_LPAR: int
TOKEN_RPAR: int
TOKEN_TRUE: int
TOKEN_FALSE: int
TOKEN_SYMBOL: int
TOKEN_TYPES: dict[int, str]

PARSE_UNKNOWN_TOKEN: int
PARSE_UNBALANCED_CLOSING_PARENS: int
PARSE_INVALID_EXPRESSION: int
PARSE_INVALID_NESTING: int
PARSE_INVALID_SYMBOL_SEQUENCE: int
PARSE_INVALID_OPERATOR_SEQUENCE: int
PARSE_ERRORS: dict[int, str]

class ParseError(Exception):
token_type: int | Symbol | None
token_string: str
position: object
error_code: int
def __init__(
self,
token_type: int | Symbol | None = None,
token_string: str = "",
position: object = -1,
error_code: int = 0,
) -> None: ...
def __str__(self, *args: object, **kwargs: object) -> str: ...

class BooleanAlgebra:
TRUE: BaseElement
FALSE: BaseElement
NOT: type[_boolean.NOT]
AND: type[_boolean.AND]
OR: type[_boolean.OR]
Symbol: type[_boolean.Symbol]
allowed_in_token: Container[str]
def __init__(
self,
TRUE_class: type[BaseElement] | None = None,
FALSE_class: type[BaseElement] | None = None,
Symbol_class: type[_boolean.Symbol] | None = None,
NOT_class: type[_boolean.NOT] | None = None,
AND_class: type[_boolean.AND] | None = None,
OR_class: type[_boolean.OR] | None = None,
allowed_in_token: Container[str] = (".", ":", "_"),
) -> None: ...
def definition(
self,
) -> tuple[
BaseElement,
BaseElement,
type[_boolean.NOT],
type[_boolean.AND],
type[_boolean.OR],
type[_boolean.Symbol],
]: ...
def symbols(self, *args: object) -> tuple[_boolean.Symbol, ...]: ...
def parse(
self,
expr: str | Iterable[tuple[int | _boolean.Symbol, str, object]],
simplify: bool = False,
) -> Expression: ...
def _start_operation(
self,
ast: list[object],
operation: type[Function],
precedence: Mapping[object, int],
) -> list[object]: ...
def tokenize(
self, expr: str
) -> Iterator[tuple[int | _boolean.Symbol, str, object]]: ...
def _recurse_distributive(
self, expr: Expression, operation_inst: DualBase
) -> Expression: ...
def normalize(
self,
expr: Expression,
operation: type[_boolean.AND] | type[_boolean.OR],
) -> Expression: ...
def cnf(self, expr: Expression) -> Expression: ...
def conjunctive_normal_form(self, expr: Expression) -> Expression: ...
def dnf(self, expr: Expression) -> Expression: ...
def disjunctive_normal_form(self, expr: Expression) -> Expression: ...

class Expression:
TRUE: ClassVar[BaseElement | None]
FALSE: ClassVar[BaseElement | None]
NOT: ClassVar[type[_boolean.NOT] | None]
AND: ClassVar[type[_boolean.AND] | None]
OR: ClassVar[type[_boolean.OR] | None]
Symbol: ClassVar[type[_boolean.Symbol] | None]
sort_order: int | None
args: tuple[Expression, ...]
isliteral: bool
iscanonical: bool
def __init__(self) -> None: ...
@property
def objects(self) -> set[object]: ...
def get_literals(self) -> list[Expression]: ...
@property
def literals(self) -> set[Expression]: ...
def literalize(self) -> Expression: ...
def get_symbols(self) -> list[_boolean.Symbol]: ...
@property
def symbols(self) -> set[_boolean.Symbol]: ...
def subs(
self,
substitutions: Mapping[Expression, Expression],
default: Expression | None = None,
simplify: bool = False,
) -> Expression: ...
def _subs(
self,
substitutions: Mapping[Expression, Expression],
default: Expression | None,
simplify: bool,
) -> Expression | None: ...
def simplify(self) -> Expression: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __and__(self, other: Expression) -> _boolean.AND: ...
def __mul__(self, other: Expression) -> _boolean.AND: ...
def __invert__(self) -> _boolean.NOT: ...
def __or__(self, other: Expression) -> _boolean.OR: ...
def __add__(self, other: Expression) -> _boolean.OR: ...
def __bool__(self) -> bool: ...
def __nonzero__(self) -> bool: ...

class BaseElement(Expression):
dual: BaseElement
def __init__(self) -> None: ...
def __lt__(self, other: object) -> bool: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> bool: ...
def pretty(self, indent: int = 0, debug: bool = False) -> str: ...

class _TRUE(BaseElement):
def __init__(self) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __call__(self) -> _TRUE: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> bool: ...

class _FALSE(BaseElement):
def __init__(self) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __call__(self) -> _FALSE: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> bool: ...

class Symbol(Expression):
obj: object
def __init__(self, obj: object) -> None: ...
def __call__(self, **kwargs: _ValueT) -> _ValueT: ...
def __hash__(self) -> int: ...
def __eq__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def pretty(self, indent: int = 0, debug: bool = False) -> str: ...

class Function(Expression):
operator: str | None
def __init__(self, *args: Expression) -> None: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def pretty(self, indent: int = 0, debug: bool = False) -> str: ...

class NOT(Function):
def __init__(self, arg1: Expression) -> None: ...
def literalize(self) -> Expression: ...
def simplify(self) -> Expression: ...
def cancel(self) -> Expression: ...
def demorgan(self) -> Expression: ...
def __call__(self, **kwargs: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def pretty(self, indent: int = 1, debug: bool = False) -> str: ...

class DualBase(Function):
_pyoperator: ClassVar[Callable[[object, object], object] | None]
identity: BaseElement
annihilator: BaseElement
dual: type[DualBase]
def __init__(
self, arg1: Expression, arg2: Expression, *args: Expression
) -> None: ...
def __contains__(self, expr: object) -> bool: ...
def simplify(self, sort: bool = True) -> Expression: ...
def flatten(self) -> DualBase: ...
def absorb(self, args: Iterable[Expression]) -> list[Expression]: ...
def subtract(self, expr: Expression, simplify: bool) -> Expression | None: ...
def distributive(self) -> Expression: ...
def __lt__(self, other: object) -> bool: ...
def __call__(self, **kwargs: _ValueT) -> _ValueT: ...

class AND(DualBase):
def __init__(
self, arg1: Expression, arg2: Expression, *args: Expression
) -> None: ...

class OR(DualBase):
def __init__(
self, arg1: Expression, arg2: Expression, *args: Expression
) -> None: ...
Empty file added boolean/py.typed
Empty file.
116 changes: 116 additions & 0 deletions boolean/test_boolean.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# The bundled test module does not define a supported library API.

import unittest

class BooleanAlgebraTestCase(unittest.TestCase):
def test_creation(self) -> None: ...
def test_parse_with_mixed_operators_multilines_and_custom_symbol(self) -> None: ...
def test_parse_recognizes_trueish_and_falsish_symbol_tokens(self) -> None: ...
def test_parse_can_use_iterable_from_alternative_tokenizer(self) -> None: ...
def test_parse_with_advanced_tokenizer_example(self) -> None: ...
def test_allowing_additional_characters_in_tokens(self) -> None: ...
def test_parse_raise_ParseError1(self) -> None: ...
def test_parse_raise_ParseError2(self) -> None: ...
def test_parse_raise_ParseError3(self) -> None: ...
def test_parse_raise_ParseError4(self) -> None: ...
def test_parse_raise_ParseError5(self) -> None: ...
def test_parse_raise_ParseError6(self) -> None: ...
def test_parse_raise_ParseError7(self) -> None: ...
def test_parse_raise_ParseError8(self) -> None: ...
def test_parse_raise_ParseError9(self) -> None: ...
def test_parse_side_by_side_symbols_should_raise_exception_but_not(
self,
) -> None: ...
def test_parse_side_by_side_symbols_should_raise_exception_but_not2(
self,
) -> None: ...
def test_parse_side_by_side_symbols_raise_exception(self) -> None: ...
def test_parse_side_by_side_symbols_with_parens_raise_exception(self) -> None: ...

class BaseElementTestCase(unittest.TestCase):
def test_creation(self) -> None: ...
def test_literals(self) -> None: ...
def test_literalize(self) -> None: ...
def test_simplify(self) -> None: ...
def test_simplify_two_algebra(self) -> None: ...
def test_dual(self) -> None: ...
def test_equality(self) -> None: ...
def test_order(self) -> None: ...
def test_printing(self) -> None: ...

class SymbolTestCase(unittest.TestCase):
def test_init(self) -> None: ...
def test_isliteral(self) -> None: ...
def test_literals(self) -> None: ...
def test_literalize(self) -> None: ...
def test_simplify(self) -> None: ...
def test_simplify_different_instances(self) -> None: ...
def test_equal_symbols(self) -> None: ...
def test_order(self) -> None: ...
def test_printing(self) -> None: ...

class NOTTestCase(unittest.TestCase):
def test_init(self) -> None: ...
def test_isliteral(self) -> None: ...
def test_literals(self) -> None: ...
def test_literalize(self) -> None: ...
def test_simplify(self) -> None: ...
def test_cancel(self) -> None: ...
def test_demorgan(self) -> None: ...
def test_order(self) -> None: ...
def test_printing(self) -> None: ...

class DualBaseTestCase(unittest.TestCase):
maxDiff: int | None
def test_init(self) -> None: ...
def test_isliteral(self) -> None: ...
def test_literals(self) -> None: ...
def test_literalize(self) -> None: ...
def test_annihilator(self) -> None: ...
def test_identity(self) -> None: ...
def test_dual(self) -> None: ...
def test_simplify(self) -> None: ...
def test_absorption_invariant_to_order(self) -> None: ...
def test_parse_complex_expression_should_create_same_expression_as_python(
self,
) -> None: ...
def test_simplify_complex_expression_parsed_with_simplify(self) -> None: ...
def test_complex_expression_without_parens_parsed_or_built_in_python_should_be_identical(
self,
) -> None: ...
def test_simplify_complex_expression_parsed_then_simplified(self) -> None: ...
def test_parse_invalid_nested_and_should_raise_a_proper_exception(self) -> None: ...
def test_subtract(self) -> None: ...
def test_flatten(self) -> None: ...
def test_distributive(self) -> None: ...
def test_equal(self) -> None: ...
def test_order(self) -> None: ...
def test_printing(self) -> None: ...

class OtherTestCase(unittest.TestCase):
def test_class_order(self) -> None: ...
def test_parse(self) -> None: ...
def test_subs(self) -> None: ...
def test_subs_default(self) -> None: ...
def test_normalize(self) -> None: ...
def test_get_literals_return_all_literals_in_original_order(self) -> None: ...
def test_get_symbols_return_all_symbols_in_original_order(self) -> None: ...
def test_literals_return_set_of_unique_literals(self) -> None: ...
def test_literals_and_negation(self) -> None: ...
def test_symbols_and_negation(self) -> None: ...
def test_objects_return_set_of_unique_Symbol_objs(self) -> None: ...
def test_normalize_blowup(self) -> None: ...

class BooleanBoolTestCase(unittest.TestCase):
def test_bool(self) -> None: ...

class CustomSymbolTestCase(unittest.TestCase):
def test_custom_symbol(self) -> None: ...

class CallabilityTestCase(unittest.TestCase):
def test_and(self) -> None: ...
def test_or(self) -> None: ...
def test_not(self) -> None: ...
def test_symbol(self) -> None: ...
def test_composite(self) -> None: ...
def test_negate_A_or_B(self) -> None: ...