PySMT 0.9.7.dev356__py2.py3-none-any.whl → 0.9.7.dev397__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. pysmt/__init__.py +6 -3
  2. pysmt/cmd/check_version.py +9 -9
  3. pysmt/cmd/install.py +1 -1
  4. pysmt/cmd/installers/__init__.py +4 -3
  5. pysmt/cmd/installers/base.py +2 -1
  6. pysmt/cmd/installers/optimsat.py +19 -11
  7. pysmt/cmd/shell.py +18 -12
  8. pysmt/constants.py +30 -24
  9. pysmt/decorators.py +6 -5
  10. pysmt/environment.py +27 -22
  11. pysmt/exceptions.py +2 -1
  12. pysmt/factory.py +76 -80
  13. pysmt/fnode.py +203 -199
  14. pysmt/formula.py +175 -153
  15. pysmt/logics.py +37 -38
  16. pysmt/operators.py +4 -3
  17. pysmt/optimization/goal.py +43 -33
  18. pysmt/optimization/optimizer.py +88 -84
  19. pysmt/optimization/optimsat.py +36 -25
  20. pysmt/optimization/z3.py +25 -14
  21. pysmt/oracles.py +64 -63
  22. pysmt/parsing.py +7 -5
  23. pysmt/printers.py +80 -74
  24. pysmt/rewritings.py +97 -92
  25. pysmt/shortcuts.py +141 -126
  26. pysmt/simplifier.py +157 -145
  27. pysmt/smtlib/annotations.py +15 -12
  28. pysmt/smtlib/parser/__init__.py +15 -9
  29. pysmt/smtlib/parser/parser.py +213 -209
  30. pysmt/smtlib/printers.py +56 -53
  31. pysmt/smtlib/script.py +74 -62
  32. pysmt/smtlib/solver.py +1 -1
  33. pysmt/smtlib/utils.py +3 -1
  34. pysmt/solvers/bdd.py +1 -1
  35. pysmt/solvers/btor.py +7 -6
  36. pysmt/solvers/cvcfive.py +42 -35
  37. pysmt/solvers/cvcfour.py +2 -5
  38. pysmt/solvers/dynmsat.py +7 -3
  39. pysmt/solvers/eager.py +8 -6
  40. pysmt/solvers/interpolation.py +8 -2
  41. pysmt/solvers/msat.py +110 -103
  42. pysmt/solvers/options.py +7 -5
  43. pysmt/solvers/pico.py +1 -1
  44. pysmt/solvers/portfolio.py +24 -17
  45. pysmt/solvers/qelim.py +16 -11
  46. pysmt/solvers/smtlib.py +31 -20
  47. pysmt/solvers/solver.py +69 -54
  48. pysmt/solvers/yices.py +60 -52
  49. pysmt/solvers/z3.py +57 -48
  50. pysmt/substituter.py +17 -15
  51. pysmt/test/__init__.py +12 -13
  52. pysmt/test/examples.py +8 -6
  53. pysmt/test/omt_examples.py +21 -2
  54. pysmt/test/optimization_utils.py +42 -28
  55. pysmt/test/smtlib/parser_utils.py +17 -10
  56. pysmt/test/smtlib/test_annotations.py +19 -17
  57. pysmt/test/smtlib/test_fuzzed.py +2 -1
  58. pysmt/test/smtlib/test_generic_wrapper.py +3 -1
  59. pysmt/test/smtlib/test_griggio.py +2 -1
  60. pysmt/test/smtlib/test_omt_lib_solver.py +2 -5
  61. pysmt/test/smtlib/test_parser_extensibility.py +9 -5
  62. pysmt/test/smtlib/test_parser_lra.py +2 -2
  63. pysmt/test/smtlib/test_parser_omt.py +5 -3
  64. pysmt/test/smtlib/test_parser_qf_arrays.py +2 -1
  65. pysmt/test/smtlib/test_parser_qf_lia.py +2 -2
  66. pysmt/test/smtlib/test_parser_qf_lira.py +2 -2
  67. pysmt/test/smtlib/test_parser_qf_lra.py +2 -2
  68. pysmt/test/smtlib/test_parser_qf_nia.py +2 -2
  69. pysmt/test/smtlib/test_parser_qf_nra.py +2 -2
  70. pysmt/test/smtlib/test_parser_qf_uf.py +2 -2
  71. pysmt/test/smtlib/test_parser_qf_ufbv.py +2 -2
  72. pysmt/test/smtlib/test_smtlibscript.py +30 -14
  73. pysmt/test/test_cnf.py +1 -1
  74. pysmt/test/test_constants.py +2 -2
  75. pysmt/test/test_formula.py +5 -5
  76. pysmt/test/test_optimizing.py +1 -4
  77. pysmt/test/test_regressions.py +1 -1
  78. pysmt/test/test_solving.py +2 -2
  79. pysmt/test/test_walker_ext.py +2 -0
  80. pysmt/type_checker.py +72 -62
  81. pysmt/typing.py +105 -121
  82. pysmt/utils.py +15 -5
  83. pysmt/walkers/__init__.py +3 -8
  84. pysmt/walkers/dag.py +16 -13
  85. pysmt/walkers/generic.py +25 -19
  86. pysmt/walkers/identitydag.py +74 -69
  87. pysmt/walkers/tree.py +6 -2
  88. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/METADATA +1 -1
  89. pysmt-0.9.7.dev397.dist-info/RECORD +152 -0
  90. pysmt-0.9.7.dev356.dist-info/RECORD +0 -152
  91. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/WHEEL +0 -0
  92. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/entry_points.txt +0 -0
  93. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/licenses/LICENSE +0 -0
  94. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/licenses/NOTICE +0 -0
  95. {pysmt-0.9.7.dev356.dist-info → pysmt-0.9.7.dev397.dist-info}/top_level.txt +0 -0
pysmt/__init__.py CHANGED
@@ -16,7 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- VERSION = (0, 9, 7, "dev", 356)
19
+ from typing import Tuple, Union
20
+
21
+
22
+ VERSION: Union[Tuple[int, int, int], Tuple[int, int, int, str, int]] = (0, 9, 7, "dev", 397)
20
23
 
21
24
  # Try to provide human-readable version of latest commit for dev versions
22
25
  # E.g. v0.5.1-4-g49a49f2-wip
@@ -32,8 +35,8 @@ if len(VERSION) == 5:
32
35
  stderr=subprocess.STDOUT)
33
36
  commits_from_tag = git_version.strip().decode('ascii')
34
37
  commits_from_tag = commits_from_tag.split("-")[1]
35
- commits_from_tag = int(commits_from_tag)
36
- VERSION = VERSION[:4] + (commits_from_tag,)
38
+ commits_from_tag_int = int(commits_from_tag)
39
+ VERSION = VERSION[:4] + (commits_from_tag_int,)
37
40
  except Exception as ex:
38
41
  pass
39
42
 
@@ -19,16 +19,16 @@ import re
19
19
  def check_version(module):
20
20
  try:
21
21
  if module == "z3":
22
- import z3
22
+ import z3 # type: ignore[import]
23
23
  (major, minor, ver, _) = z3.get_version()
24
24
  version = "%d.%d.%d" % (major, minor, ver)
25
25
 
26
26
  elif module in ("msat", "optimsat"):
27
27
  if module == "msat":
28
- import mathsat
28
+ import mathsat # type: ignore[import]
29
29
  version_str = mathsat.msat_get_version()
30
30
  else:
31
- import optimathsat
31
+ import optimathsat # type: ignore[import]
32
32
  version_str = optimathsat.msat_get_version()
33
33
  m = re.match(r"^MathSAT5 version (\d+\.\d+\.\d+) .*$", version_str)
34
34
  if m is not None:
@@ -39,31 +39,31 @@ def check_version(module):
39
39
  version = m.group(1)
40
40
 
41
41
  elif module == "cudd":
42
- import repycudd
42
+ import repycudd # type: ignore[import]
43
43
  doc = repycudd.DOCSTRING
44
44
  m = re.match(r"^PyCUDD (\d+\.\d+\.\d+).*", doc)
45
45
  if m is not None:
46
46
  version = m.group(1)
47
47
 
48
48
  elif module == "btor":
49
- import pyboolector
49
+ import pyboolector # type: ignore[import]
50
50
  version = "OK" # Just checking if import succeeds
51
51
 
52
52
  elif module == "cvc5":
53
- import cvc5
53
+ import cvc5 # type: ignore[import]
54
54
  solver = cvc5.Solver()
55
55
  version = solver.getVersion().decode('ascii')
56
56
 
57
57
  elif module == "cvc4":
58
- import CVC4
58
+ import CVC4 # type: ignore[import]
59
59
  version = CVC4.Configuration_getVersionString()
60
60
 
61
61
  elif module == "picosat":
62
- import picosat
62
+ import picosat # type: ignore[import]
63
63
  version = picosat.picosat_version()
64
64
 
65
65
  elif module == "yices":
66
- import yices_api
66
+ import yices_api # type: ignore[import]
67
67
  version = yices_api.yices_python_version
68
68
  else:
69
69
  print("Invalid argument '%s'" % module)
pysmt/cmd/install.py CHANGED
@@ -43,7 +43,7 @@ INSTALLERS = [
43
43
  {"pypicosat_minor_version" : "1708010052"}),
44
44
  Installer(CuddInstaller, "2.0.3",
45
45
  {"git_version" : "ecb03d6d231273343178f566cc4d7258dcce52b4"}),
46
- Installer(OptiMSatInstaller, "1.7.3", {})
46
+ Installer(OptiMSatInstaller, "1.7.5", {})
47
47
  ]
48
48
 
49
49
 
@@ -22,6 +22,7 @@ from pysmt.cmd.installers.pico import PicoSATInstaller
22
22
  from pysmt.cmd.installers.bdd import CuddInstaller
23
23
  from pysmt.cmd.installers.optimsat import OptiMSatInstaller
24
24
 
25
- assert MSatInstaller and Z3Installer and CVC5Installer and YicesInstaller
26
- assert BtorInstaller and PicoSATInstaller and CuddInstaller and CVC4Installer
27
- assert OptiMSatInstaller
25
+ # asserts to use the imported variables. Done to avoid the unused variables warning
26
+ assert MSatInstaller and Z3Installer and CVC5Installer and YicesInstaller # type: ignore [truthy-function]
27
+ assert BtorInstaller and PicoSATInstaller and CuddInstaller and CVC4Installer # type: ignore [truthy-function]
28
+ assert OptiMSatInstaller # type: ignore [truthy-function]
@@ -23,6 +23,7 @@ import urllib.request
23
23
 
24
24
  from contextlib import contextmanager
25
25
  from setuptools import Distribution
26
+ from typing import Optional
26
27
 
27
28
  from urllib.error import HTTPError, URLError
28
29
 
@@ -40,7 +41,7 @@ def TemporaryPath(path):
40
41
 
41
42
  class SolverInstaller(object):
42
43
 
43
- SOLVER = None
44
+ SOLVER: Optional[str] = None
44
45
 
45
46
  def __init__(self, install_dir, bindings_dir, solver_version,
46
47
  archive_name=None, native_link=None, mirror_link=None):
@@ -24,18 +24,26 @@ class OptiMSatInstaller(SolverInstaller):
24
24
 
25
25
  def __init__(self, install_dir, bindings_dir, solver_version,
26
26
  mirror_link=None):
27
+
27
28
  # Getting the right archive name
28
- os_name = self.os_name
29
- arch = str(self.bits) + "-bit"
30
- ext = "tar.gz"
31
- if os_name == "windows":
32
- ext = "zip"
33
- arch += "-mingw"
34
- elif os_name == "darwin":
35
- os_name = "macos"
36
-
37
- archive_name = "optimathsat-%s-%s-%s.%s" % (solver_version, os_name,
38
- arch, ext)
29
+ archive_name_template = "optimathsat-{version}-{os}-{arch}.{ext}"
30
+ format = {
31
+ "version": solver_version,
32
+ "os" : self.os_name,
33
+ "arch": self.architecture,
34
+ "ext": "tar.gz"
35
+ }
36
+ if self.os_name in ["windows", "darwin"]:
37
+ # Since version 1.7.5 the architecture is not included in the
38
+ # pkg name for the OSX and Win release as it is considered a "universal binary"
39
+ archive_name_template = "optimathsat-{version}-{os}.{ext}"
40
+ if self.os_name == "windows":
41
+ format["ext"] = "zip"
42
+ format["os"] = "win64" if self.architecture == "x86_64" else "win32"
43
+ elif self.os_name == "darwin":
44
+ format["os"] = "osx"
45
+
46
+ archive_name = archive_name_template.format(**format)
39
47
 
40
48
  native_link = "https://optimathsat.disi.unitn.it/releases/optimathsat-%s/{archive_name}" % solver_version
41
49
 
pysmt/cmd/shell.py CHANGED
@@ -20,15 +20,20 @@
20
20
  import sys
21
21
  import argparse
22
22
  from warnings import warn
23
+ from io import StringIO
24
+ from typing import Any, List
23
25
 
26
+ import pysmt.solvers
24
27
  from pysmt import __version__
25
28
  from pysmt.shortcuts import *
26
- from pysmt.typing import INT, REAL, BOOL, BVType, BV32
27
-
29
+ from pysmt.logics import PYSMT_LOGICS
28
30
  from pysmt.smtlib.parser import SmtLibParser
29
- from pysmt.smtlib.script import InterpreterOMT, InterpreterSMT
31
+ from pysmt.smtlib.script import SmtLibCommand, InterpreterOMT, InterpreterSMT
30
32
  from pysmt.smtlib.commands import CHECK_SAT, GET_VALUE, GET_OBJECTIVES, ECHO
31
- from pysmt.logics import PYSMT_LOGICS
33
+ from pysmt.solvers.smtlib import SmtLibSolver
34
+ from pysmt.typing import INT, REAL, BOOL, BVType, BV32
35
+ # assert done to use variables for handier export
36
+ assert INT or REAL or BOOL or BVType or BV32 # type: ignore[truthy-function]
32
37
 
33
38
  welcome_msg = \
34
39
  """Welcome to pySMT!!!
@@ -58,7 +63,7 @@ Happy Solving!
58
63
 
59
64
  class PysmtShell(object):
60
65
 
61
- def __init__(self, argv):
66
+ def __init__(self, argv: List[str]):
62
67
  self.env = get_env()
63
68
  self.solvers = list(self.env.factory.all_solvers().keys())
64
69
  self.optimizers = list(self.env.factory.all_optimizers().keys())
@@ -66,7 +71,7 @@ class PysmtShell(object):
66
71
  self.args = self.parser.parse_args(argv)
67
72
 
68
73
 
69
- def get_parser(self):
74
+ def get_parser(self) -> argparse.ArgumentParser:
70
75
  parser = argparse.ArgumentParser(description="Command-line interface " \
71
76
  "for pySMT problems")
72
77
  parser.add_argument('--version', action='version',
@@ -97,7 +102,7 @@ class PysmtShell(object):
97
102
  # Enable infix notation in Interactive mode
98
103
  get_env().enable_infix_notation = True
99
104
  try:
100
- import IPython
105
+ import IPython # type: ignore
101
106
  print(welcome_msg)
102
107
  IPython.embed()
103
108
  except ImportError:
@@ -105,13 +110,13 @@ class PysmtShell(object):
105
110
  code.interact(welcome_msg)
106
111
 
107
112
 
108
- def _print(self, val, stream_out):
113
+ def _print(self, val: str, stream_out: StringIO):
109
114
  stream_out.write(val)
110
115
  stream_out.write("\n")
111
116
  stream_out.flush()
112
117
 
113
118
 
114
- def print_result(self, stream_out, cmd, result):
119
+ def print_result(self, stream_out: StringIO, cmd: SmtLibCommand, result: Any):
115
120
  name, _ = cmd
116
121
  if name == ECHO:
117
122
  self._print(result, stream_out)
@@ -132,7 +137,7 @@ class PysmtShell(object):
132
137
  self._print(")", stream_out)
133
138
 
134
139
 
135
- def smtlib_solver(self, stream_in, stream_out):
140
+ def smtlib_solver(self, stream_in: StringIO, stream_out: StringIO):
136
141
  smt_parser = SmtLibParser()
137
142
  s_name = self.args.solver
138
143
  opt_name = self.args.optimizer
@@ -142,10 +147,10 @@ class PysmtShell(object):
142
147
 
143
148
  if opt_name is not None:
144
149
  if opt_name == "auto":
145
- solver = Optimizer(logic=logic)
150
+ solver: "pysmt.solvers.solver.Solver" = Optimizer(logic=logic)
146
151
  else:
147
152
  solver = Optimizer(name=opt_name, logic=logic)
148
- inter = InterpreterOMT()
153
+ inter: InterpreterSMT = InterpreterOMT()
149
154
  else:
150
155
  if s_name == "auto":
151
156
  solver = Solver(logic=logic)
@@ -153,6 +158,7 @@ class PysmtShell(object):
153
158
  solver = Solver(name=s_name, logic=logic)
154
159
  inter = InterpreterSMT()
155
160
  for cmd in smt_parser.get_command_generator(stream_in):
161
+ assert isinstance(solver, SmtLibSolver)
156
162
  r = inter.evaluate(cmd, solver)
157
163
  self.print_result(stream_out, cmd, r)
158
164
 
pysmt/constants.py CHANGED
@@ -16,7 +16,10 @@
16
16
 
17
17
  import os
18
18
 
19
+ from typing import Any, Optional, Type, Union, cast
20
+
19
21
  from pysmt.exceptions import PysmtImportError
22
+
20
23
  # The environment variable can be used to force the configuration
21
24
  # of the Fraction class.
22
25
  #
@@ -29,13 +32,14 @@ from pysmt.exceptions import PysmtImportError
29
32
  # If set to True, Python's Fraction module will be used instead.
30
33
  #
31
34
 
32
- ENV_USE_GMPY = os.environ.get("PYSMT_GMPY")
33
- if ENV_USE_GMPY is not None:
34
- ENV_USE_GMPY = ENV_USE_GMPY.lower() in ["true", "1"]
35
+ ENV_USE_GMPY: Optional[bool] = None
36
+ env_use_gmpy_val = os.environ.get("PYSMT_GMPY")
37
+ if env_use_gmpy_val is not None:
38
+ ENV_USE_GMPY = env_use_gmpy_val.lower() in ["true", "1"]
35
39
 
36
40
  HAS_GMPY = False
37
41
  try:
38
- from gmpy2 import mpq, mpz
42
+ from gmpy2 import mpq, mpz # type: ignore[import]
39
43
  HAS_GMPY = True
40
44
  except ImportError as ex:
41
45
  if ENV_USE_GMPY is True:
@@ -52,8 +56,8 @@ else:
52
56
  USE_GMPY = HAS_GMPY
53
57
 
54
58
  if HAS_GMPY:
55
- mpq_type = type(mpq(1,2))
56
- mpz_type = type(mpz(1))
59
+ mpq_type: Optional[Type[Any]] = type(mpq(1,2))
60
+ mpz_type: Optional[Type[Any]] = type(mpz(1))
57
61
  else:
58
62
  mpq_type = None
59
63
  mpz_type = None
@@ -67,10 +71,11 @@ if USE_GMPY:
67
71
  Fraction = mpq
68
72
  else:
69
73
  Fraction = pyFraction
74
+
70
75
  FractionClass = type(Fraction(1,2))
71
76
 
72
77
 
73
- def is_pysmt_fraction(var):
78
+ def is_pysmt_fraction(var: Any) -> bool:
74
79
  """Tests whether var is a Fraction.
75
80
 
76
81
  This takes into account the class being used to represent the Fraction.
@@ -87,7 +92,7 @@ else:
87
92
  IntegerClass = type(Integer(1))
88
93
 
89
94
 
90
- def is_pysmt_integer(var):
95
+ def is_pysmt_integer(var: Any) -> bool:
91
96
  """Tests whether var is an Integer.
92
97
 
93
98
  This takes into account the class being used to represent the Integer.
@@ -95,7 +100,7 @@ def is_pysmt_integer(var):
95
100
  return type(var) == IntegerClass
96
101
 
97
102
 
98
- def is_python_integer(var):
103
+ def is_python_integer(var: Any) -> bool:
99
104
  """Checks whether var is Python Integer.
100
105
 
101
106
  This accounts for: long, int and mpz (if available).
@@ -107,7 +112,7 @@ def is_python_integer(var):
107
112
  return False
108
113
 
109
114
 
110
- def is_python_rational(var):
115
+ def is_python_rational(var: Any) -> bool:
111
116
  """Tests whether var is a Rational.
112
117
 
113
118
  This accounts for: long, int, float, Fraction, mpz, mpq (if available).
@@ -123,7 +128,7 @@ def is_python_rational(var):
123
128
  return False
124
129
 
125
130
 
126
- def is_python_boolean(var):
131
+ def is_python_boolean(var: Any):
127
132
  """Tests whether var is a Boolean."""
128
133
  return var is True or var is False
129
134
 
@@ -142,28 +147,29 @@ def to_python_integer(value):
142
147
 
143
148
 
144
149
  if USE_GMPY:
145
- def pysmt_fraction_from_rational(value):
150
+ def pysmt_fraction_from_rational(value: Union[float, int, pyFraction]) -> pyFraction:
146
151
  """Return a pysmt Fraction for the rational value."""
147
152
  if type(value) == FractionClass:
148
153
  # Nothing to do
149
- return value
150
- return Fraction(value)
154
+ return cast(pyFraction, value)
155
+ return cast(pyFraction, FractionClass(value))
151
156
  else:
152
- def pysmt_fraction_from_rational(value):
157
+ def pysmt_fraction_from_rational(value: Union[float, int, pyFraction]) -> pyFraction:
153
158
  """Return a pysmt Fraction for the rational value."""
154
159
  if type(value) == FractionClass:
155
160
  # Nothing to do
156
- return value
161
+ return cast(pyFraction, value)
157
162
  # Python's Fraction is a bit picky, need to
158
163
  # construct the object in different ways
159
164
  if type(value) == mpq_type:
160
- n = Integer(value.numerator())
161
- d = Integer(value.denominator())
162
- return Fraction(n, d)
165
+ val = cast(Any, value)
166
+ n = Integer(val.numerator())
167
+ d = Integer(val.denominator())
168
+ return cast(pyFraction, Fraction(n, d))
163
169
  elif type(value) == mpz_type:
164
- return Fraction(Integer(value))
170
+ return cast(pyFraction, Fraction(Integer(value)))
165
171
  else:
166
- return Fraction(value)
172
+ return cast(pyFraction, Fraction(value))
167
173
 
168
174
  #
169
175
  # Algebraic Numbers Using Z3
@@ -171,7 +177,7 @@ else:
171
177
 
172
178
  USE_Z3 = False
173
179
  try:
174
- import z3.z3num
180
+ import z3.z3num # type: ignore[import]
175
181
  USE_Z3 = True
176
182
  except ImportError:
177
183
  pass
@@ -192,7 +198,7 @@ if USE_Z3:
192
198
  pass
193
199
 
194
200
  else:
195
- class Numeral(object):
201
+ class Numeral(object): # type: ignore[no-redef]
196
202
  """Represents a Number (Algebraic)"""
197
203
  def __init__(self, obj):
198
204
  raise NotImplementedError("Z3 is not installed. "\
@@ -201,5 +207,5 @@ else:
201
207
  #
202
208
  # Strings
203
209
  #
204
- def is_python_string(str1):
210
+ def is_python_string(str1: str) -> bool:
205
211
  return type(str1) == str
pysmt/decorators.py CHANGED
@@ -19,16 +19,17 @@ from functools import wraps
19
19
  import warnings
20
20
 
21
21
  import pysmt.exceptions
22
+ from typing import Callable, Optional
22
23
 
23
24
  class deprecated(object):
24
25
  """This is a decorator which can be used to mark functions
25
26
  as deprecated. It will result in a warning being emitted
26
27
  when the function is used."""
27
28
 
28
- def __init__(self, alternative=None):
29
+ def __init__(self, alternative: Optional[str]=None):
29
30
  self.alternative = alternative
30
31
 
31
- def __call__(self, func):
32
+ def __call__(self, func: Callable) -> Callable:
32
33
  def newFunc(*args, **kwargs):
33
34
  alt = ""
34
35
  if self.alternative is not None:
@@ -44,7 +45,7 @@ class deprecated(object):
44
45
  return newFunc
45
46
 
46
47
 
47
- def clear_pending_pop(f):
48
+ def clear_pending_pop(f: Callable) -> Callable:
48
49
  """Pop the solver stack (if necessary) before calling the function.
49
50
 
50
51
  Some functions (e.g., get_value) required the state of the solver
@@ -75,7 +76,7 @@ def typecheck_result(f):
75
76
  return typecheck_result_wrap
76
77
 
77
78
 
78
- def catch_conversion_error(f):
79
+ def catch_conversion_error(f: Callable) -> Callable:
79
80
  """Catch unknown operators errors and converts them into conversion error."""
80
81
 
81
82
  @wraps(f)
@@ -92,7 +93,7 @@ def catch_conversion_error(f):
92
93
  return catch_conversion_error_wrap
93
94
 
94
95
 
95
- def assert_infix_enabled(f):
96
+ def assert_infix_enabled(f: Callable) -> Callable:
96
97
  """Raise an exception if infix notation is not enabled."""
97
98
  from functools import wraps
98
99
  from pysmt.exceptions import PysmtModeError
pysmt/environment.py CHANGED
@@ -21,14 +21,14 @@ singleton objects that are used throughout the system, such as the
21
21
  FormulaManager, Simplifier, HRSerializer, SimpleTypeChecker.
22
22
  """
23
23
 
24
+ from typing import List, Optional
25
+
24
26
  import pysmt.simplifier
25
27
  import pysmt.printers
26
28
  import pysmt.substituter
27
29
  import pysmt.type_checker
28
30
  import pysmt.oracles
29
31
  import pysmt.formula
30
- import pysmt.factory
31
- import pysmt.decorators
32
32
  import pysmt.typing
33
33
 
34
34
 
@@ -41,11 +41,12 @@ class Environment(object):
41
41
  of classes for the different services, by changing the class
42
42
  attributes.
43
43
  """
44
+
44
45
  TypeCheckerClass = pysmt.type_checker.SimpleTypeChecker
45
46
  FormulaManagerClass = pysmt.formula.FormulaManager
46
47
  TypeManagerClass = pysmt.typing.TypeManager
47
48
  SimplifierClass = pysmt.simplifier.Simplifier
48
- #SubstituterClass = pysmt.substituter.MSSubstituter
49
+ # SubstituterClass = pysmt.substituter.MSSubstituter
49
50
  SubstituterClass = pysmt.substituter.MGSubstituter
50
51
  HRSerializerClass = pysmt.printers.HRSerializer
51
52
  QuantifierOracleClass = pysmt.oracles.QuantifierOracle
@@ -91,57 +92,57 @@ class Environment(object):
91
92
  self.dwf = {}
92
93
 
93
94
  @property
94
- def formula_manager(self):
95
+ def formula_manager(self) -> pysmt.formula.FormulaManager:
95
96
  return self._formula_manager
96
97
 
97
98
  @property
98
- def type_manager(self):
99
+ def type_manager(self) -> pysmt.typing.TypeManager:
99
100
  return self._type_manager
100
101
 
101
102
  @property
102
- def simplifier(self):
103
+ def simplifier(self) -> pysmt.simplifier.Simplifier:
103
104
  return self._simplifier
104
105
 
105
106
  @property
106
- def serializer(self):
107
+ def serializer(self) -> pysmt.printers.HRSerializer:
107
108
  return self._serializer
108
109
 
109
110
  @property
110
- def substituter(self):
111
+ def substituter(self) -> pysmt.substituter.Substituter:
111
112
  return self._substituter
112
113
 
113
114
  @property
114
- def stc(self):
115
+ def stc(self) -> pysmt.type_checker.SimpleTypeChecker:
115
116
  """ Get the Simple Type Checker """
116
117
  return self._stc
117
118
 
118
119
  @property
119
- def qfo(self):
120
+ def qfo(self) -> pysmt.oracles.QuantifierOracle:
120
121
  """ Get the Quantifier Oracle """
121
122
  return self._qfo
122
123
 
123
124
  @property
124
- def ao(self):
125
+ def ao(self) -> pysmt.oracles.AtomsOracle:
125
126
  """ Get the Atoms Oracle """
126
127
  return self._ao
127
128
 
128
129
  @property
129
- def theoryo(self):
130
+ def theoryo(self) -> pysmt.oracles.TheoryOracle:
130
131
  """ Get the Theory Oracle """
131
132
  return self._theoryo
132
133
 
133
134
  @property
134
- def typeso(self):
135
+ def typeso(self) -> pysmt.oracles.TypesOracle:
135
136
  """ Get the Types Oracle """
136
137
  return self._typeso
137
138
 
138
139
  @property
139
- def fvo(self):
140
+ def fvo(self) -> pysmt.oracles.FreeVarsOracle:
140
141
  """ Get the FreeVars Oracle """
141
142
  return self._fvo
142
143
 
143
144
  @property
144
- def sizeo(self):
145
+ def sizeo(self) -> pysmt.oracles.SizeOracle:
145
146
  """ Get the Size Oracle """
146
147
  return self._sizeo
147
148
 
@@ -164,12 +165,13 @@ class Environment(object):
164
165
  self.dwf[nodetype][walker] = function
165
166
 
166
167
  @property
167
- def factory(self):
168
+ def factory(self) -> "pysmt.factory.Factory":
169
+ import pysmt.factory
168
170
  if self._factory is None:
169
171
  self._factory = pysmt.factory.Factory(self)
170
172
  return self._factory
171
173
 
172
- def __enter__(self):
174
+ def __enter__(self) -> "Environment":
173
175
  """Entering a Context """
174
176
  push_env(self)
175
177
  return self
@@ -181,23 +183,26 @@ class Environment(object):
181
183
  # EOC Environment
182
184
 
183
185
  #### GLOBAL ENVIRONMENTS STACKS ####
184
- ENVIRONMENTS_STACK = []
186
+ ENVIRONMENTS_STACK: List[Environment] = []
185
187
 
186
- def get_env():
188
+ def get_env() -> Environment:
187
189
  """Returns the Environment at the head of the stack."""
188
190
  return ENVIRONMENTS_STACK[-1]
189
191
 
190
- def push_env(env=None):
192
+
193
+ def push_env(env: Optional[Environment] = None):
191
194
  """Push a env in the stack. If env is None, a new Environment is created."""
192
195
  if env is None:
193
196
  env = Environment()
194
197
  ENVIRONMENTS_STACK.append(env)
195
198
 
196
- def pop_env():
199
+
200
+ def pop_env() -> Environment:
197
201
  """Pop an env from the stack."""
198
202
  return ENVIRONMENTS_STACK.pop()
199
203
 
200
- def reset_env():
204
+
205
+ def reset_env() -> Environment:
201
206
  """Destroys and recreate the head environment."""
202
207
  pop_env()
203
208
  push_env()
pysmt/exceptions.py CHANGED
@@ -18,6 +18,7 @@
18
18
  """This module contains all custom exceptions of pySMT."""
19
19
 
20
20
  import pysmt.operators as op
21
+ from typing import Optional, Tuple
21
22
 
22
23
 
23
24
  class PysmtException(Exception):
@@ -134,7 +135,7 @@ class PysmtTypeError(PysmtException, TypeError):
134
135
  pass
135
136
 
136
137
  class PysmtSyntaxError(PysmtException, SyntaxError):
137
- def __init__(self, message, pos_info=None):
138
+ def __init__(self, message: str, pos_info: Optional[Tuple[int, int]]=None):
138
139
  super(PysmtSyntaxError, self).__init__(message)
139
140
  self.pos_info = pos_info
140
141
  self.message = message