Skip to content

Commit

Permalink
Support Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxxyz committed Jun 11, 2019
1 parent 1fa3b8e commit 484c6e9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist: xenial
language: python

python:
- "3.6"
- "3.7"

install:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This package takes much of its data model and terminology from
pip install nnf
```

Only Python 3.7 or higher is currently supported.
At least Python 3.6 is required.

# Serialization

Expand Down
22 changes: 10 additions & 12 deletions nnf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from __future__ import annotations

import functools
import itertools
import typing as t
Expand Down Expand Up @@ -57,15 +55,15 @@ def all_models(names: t.Collection[Name]) -> t.Iterator[Model]:
class NNF:
"""Base class for all NNF sentences."""

def __and__(self, other: NNF) -> NNF:
def __and__(self, other: 'NNF') -> 'NNF':
"""And({self, other})"""
return And({self, other})

def __or__(self, other: NNF) -> NNF:
def __or__(self, other: 'NNF') -> 'NNF':
"""Or({self, other})"""
return Or({self, other})

def walk(self) -> t.Iterator[NNF]:
def walk(self) -> t.Iterator['NNF']:
"""Yield all nodes in the sentence, depth-first.
Nodes that appear multiple times are yielded only once.
Expand Down Expand Up @@ -256,7 +254,7 @@ def models(self, decomposable: _Tristate = None) -> t.Iterator[Model]:
if self.satisfied_by(model):
yield model

def contradicts(self, other: NNF) -> bool:
def contradicts(self, other: 'NNF') -> bool:
"""There is no set of values that satisfies both sentences."""
if self.vars() != other.vars():
raise ValueError("Sentences mention different variables")
Expand All @@ -267,7 +265,7 @@ def contradicts(self, other: NNF) -> bool:
return False
return True

def to_MODS(self) -> NNF:
def to_MODS(self) -> 'NNF':
"""Convert the sentence to a MODS sentence."""
return Or(And(Var(name, val)
for name, val in model.items())
Expand Down Expand Up @@ -295,7 +293,7 @@ def to_model(self) -> Model:

return model

def condition(self, model: Model) -> NNF:
def condition(self, model: Model) -> 'NNF':
"""Fill in all the values in the dictionary."""
@memoize
def cond(node: NNF) -> NNF:
Expand All @@ -315,7 +313,7 @@ def cond(node: NNF) -> NNF:

return cond(self)

def simplify(self) -> NNF:
def simplify(self) -> 'NNF':
"""Apply the following transformations to make the sentence simpler:
- If an And node has `false` as a child, replace it by `false`
Expand Down Expand Up @@ -367,7 +365,7 @@ def simple(node: NNF) -> NNF:

return simple(self)

def deduplicate(self) -> NNF:
def deduplicate(self) -> 'NNF':
"""Return a copy of the sentence without any duplicate objects.
If a node has multiple parents, it's possible for it to be
Expand Down Expand Up @@ -464,7 +462,7 @@ def name(node: NNF) -> int:

def transform(
self,
func: t.Callable[[t.Callable[[NNF], T], NNF], T]
func: t.Callable[[t.Callable[['NNF'], T], 'NNF'], T]
) -> T:
"""A helper function to apply a transformation with memoization.
Expand Down Expand Up @@ -625,7 +623,7 @@ def __repr__(self) -> str:
base = f"{self.__class__.__name__}({self.name!r})"
return base if self.true else f"~{base}"

def __invert__(self) -> Var:
def __invert__(self) -> 'Var':
return Var(self.name, not self.true)


Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="nnf",
version="0.0.2",
version="0.0.3",
author="Jan Verbeek",
author_email="[email protected]",
description="Manipulate NNF (Negation Normal Form) logical sentences",
Expand All @@ -21,6 +21,7 @@
"Development Status :: 2 - Pre-Alpha",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3 :: Only",
"License :: OSI Approved :: ISC License (ISCL)",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37
envlist = py36, py37

[testenv]
deps =
Expand Down

0 comments on commit 484c6e9

Please sign in to comment.