crosshair-tool 0.0.93__cp38-cp38-win_amd64.whl → 0.0.94__cp38-cp38-win_amd64.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.

Potentially problematic release.


This version of crosshair-tool might be problematic. Click here for more details.

Binary file
crosshair/__init__.py CHANGED
@@ -15,7 +15,7 @@ from crosshair.statespace import StateSpace
15
15
  from crosshair.tracers import NoTracing, ResumedTracing
16
16
  from crosshair.util import IgnoreAttempt, debug
17
17
 
18
- __version__ = "0.0.93" # Do not forget to update in setup.py!
18
+ __version__ = "0.0.94" # Do not forget to update in setup.py!
19
19
  __author__ = "Phillip Schanely"
20
20
  __license__ = "MIT"
21
21
  __status__ = "Alpha"
crosshair/core.py CHANGED
@@ -127,6 +127,14 @@ from crosshair.util import (
127
127
  warn,
128
128
  )
129
129
 
130
+ if sys.version_info >= (3, 12):
131
+ from typing import TypeAliasType
132
+
133
+ TypeAliasTypes = (TypeAliasType,)
134
+ else:
135
+ TypeAliasTypes = ()
136
+
137
+
130
138
  _MISSING = object()
131
139
 
132
140
 
@@ -667,6 +675,11 @@ def proxy_for_type(
667
675
  typ = normalize_pytype(typ)
668
676
  origin = origin_of(typ)
669
677
  type_args = type_args_of(typ)
678
+ while isinstance(origin, TypeAliasTypes):
679
+ type_var_bindings = dict(zip(origin.__type_params__, type_args))
680
+ unified = dynamic_typing.realize(origin.__value__, type_var_bindings)
681
+ return proxy_for_type(unified, varname, allow_subtypes)
682
+
670
683
  # special cases
671
684
  if isinstance(typ, type) and issubclass(typ, enum.Enum):
672
685
  enum_values = list(typ) # type:ignore
crosshair/core_test.py CHANGED
@@ -5,6 +5,7 @@ import re
5
5
  import sys
6
6
  import time
7
7
  from typing import *
8
+ from unittest import skipIf
8
9
 
9
10
  import pytest # type: ignore
10
11
 
@@ -28,7 +29,7 @@ from crosshair.core_and_libs import (
28
29
  standalone_statespace,
29
30
  )
30
31
  from crosshair.fnutil import FunctionInfo, walk_qualname
31
- from crosshair.libimpl.builtinslib import SymbolicInt
32
+ from crosshair.libimpl.builtinslib import LazyIntSymbolicStr, SymbolicInt
32
33
  from crosshair.options import DEFAULT_OPTIONS, AnalysisOptionSet
33
34
  from crosshair.statespace import (
34
35
  CANNOT_CONFIRM,
@@ -735,6 +736,29 @@ def test_newtype() -> None:
735
736
  assert isinstance(x, SymbolicInt)
736
737
 
737
738
 
739
+ @skipIf(sys.version_info < (3, 12), "type statements added in 3.12")
740
+ def test_type_statement() -> None:
741
+ env: dict[str, Any] = {}
742
+ exec("type MyIntNew = int\n", env)
743
+ assert "MyIntNew" in env
744
+ MyIntNew = env["MyIntNew"]
745
+ with standalone_statespace:
746
+ x = proxy_for_type(MyIntNew, "x")
747
+ assert isinstance(x, SymbolicInt)
748
+
749
+
750
+ @skipIf(sys.version_info < (3, 12), "type statements added in 3.12")
751
+ def test_parameterized_type_statement() -> None:
752
+ env: dict[str, Any] = {}
753
+ exec("type Pair[A, B] = tuple[B, A]\n", env)
754
+ assert "Pair" in env
755
+ Pair = env["Pair"]
756
+ with standalone_statespace:
757
+ x = proxy_for_type(Pair[int, str], "x")
758
+ assert isinstance(x[0], LazyIntSymbolicStr)
759
+ assert isinstance(x[1], SymbolicInt)
760
+
761
+
738
762
  def test_container_typevar() -> None:
739
763
  T = TypeVar("T")
740
764
 
@@ -1,4 +1,5 @@
1
1
  import collections.abc
2
+ import sys
2
3
  import typing
3
4
  from inspect import Parameter, Signature
4
5
  from itertools import zip_longest
@@ -223,21 +224,41 @@ def get_bindings_from_type_arguments(pytype: Type) -> Mapping[object, type]:
223
224
  return {}
224
225
 
225
226
 
226
- def realize(pytype: Type, bindings: Mapping[object, type]) -> object:
227
- if typing_inspect.is_typevar(pytype):
228
- return bindings[pytype]
229
- if not hasattr(pytype, "__args__"):
230
- return pytype
231
- newargs: List = []
232
- for arg in pytype.__args__: # type:ignore
233
- newargs.append(realize(arg, bindings))
234
- # print('realizing pytype', repr(pytype), 'newargs', repr(newargs))
235
- pytype_origin = origin_of(pytype)
236
- if not hasattr(pytype_origin, "_name"):
237
- pytype_origin = getattr(typing, pytype._name) # type:ignore
238
- if pytype_origin is Callable: # Callable args get flattened
239
- newargs = [newargs[:-1], newargs[-1]]
240
- return pytype_origin.__getitem__(tuple(newargs))
227
+ if sys.version_info >= (3, 9):
228
+
229
+ def realize(pytype: Type, bindings: Mapping[object, type]) -> object:
230
+ if typing_inspect.is_typevar(pytype):
231
+ return bindings[pytype]
232
+ if not hasattr(pytype, "__args__"):
233
+ return pytype
234
+ newargs: List = []
235
+ for arg in pytype.__args__: # type:ignore
236
+ newargs.append(realize(arg, bindings))
237
+ pytype_origin = origin_of(pytype)
238
+ if pytype_origin in (
239
+ collections.abc.Callable,
240
+ typing.Callable,
241
+ ): # Callable args get flattened
242
+ newargs = [newargs[:-1], newargs[-1]]
243
+ return pytype_origin.__class_getitem__(tuple(newargs))
244
+
245
+ else:
246
+
247
+ def realize(pytype: Type, bindings: Mapping[object, type]) -> object:
248
+ if typing_inspect.is_typevar(pytype):
249
+ return bindings[pytype]
250
+ if not hasattr(pytype, "__args__"):
251
+ return pytype
252
+ newargs: List = []
253
+ for arg in pytype.__args__: # type:ignore
254
+ newargs.append(realize(arg, bindings))
255
+ # print('realizing pytype', repr(pytype), 'newargs', repr(newargs))
256
+ pytype_origin = origin_of(pytype)
257
+ if not hasattr(pytype_origin, "_name"):
258
+ pytype_origin = getattr(typing, pytype._name) # type:ignore
259
+ if pytype_origin is Callable: # Callable args get flattened
260
+ newargs = [newargs[:-1], newargs[-1]]
261
+ return pytype_origin.__getitem__(tuple(newargs))
241
262
 
242
263
 
243
264
  def isolate_var_params(
@@ -1,4 +1,5 @@
1
1
  import collections
2
+ import sys
2
3
  from inspect import Parameter, Signature, signature
3
4
  from typing import (
4
5
  Callable,
@@ -60,7 +61,12 @@ def test_typedicts():
60
61
  def test_typevars():
61
62
  bindings = collections.ChainMap()
62
63
  assert unify(Tuple[int, str, List[int]], Tuple[int, _T, _U], bindings)
63
- assert realize(Mapping[_U, _T], bindings) == Mapping[List[int], str]
64
+
65
+ ret = realize(Mapping[_U, _T], bindings)
66
+ if sys.version_info >= (3, 9):
67
+ assert ret == collections.abc.Mapping[List[int], str]
68
+ else:
69
+ assert ret == Mapping[List[int], str]
64
70
 
65
71
 
66
72
  def test_bound_vtypears():
@@ -79,7 +85,13 @@ def test_callable():
79
85
 
80
86
  assert not unify(Callable[[List], bool], Callable[[Iterable], bool], bindings)
81
87
  assert unify(Callable[[int, _T], List[int]], Callable[[int, str], _U], bindings)
82
- assert realize(Callable[[_U], _T], bindings) == Callable[[List[int]], str]
88
+ if sys.version_info >= (3, 9):
89
+ assert (
90
+ realize(Callable[[_U], _T], bindings)
91
+ == collections.abc.Callable[[List[int]], str]
92
+ )
93
+ else:
94
+ assert realize(Callable[[_U], _T], bindings) == Callable[[List[int]], str]
83
95
 
84
96
 
85
97
  def test_plain_callable():
@@ -131,7 +143,10 @@ class Pair(Generic[_U, _T]):
131
143
  def test_bindings_from_type_arguments():
132
144
  var_mapping = get_bindings_from_type_arguments(Pair[int, str])
133
145
  assert var_mapping == {_U: int, _T: str}
134
- assert realize(List[_U], var_mapping) == List[int]
146
+ if sys.version_info >= (3, 9):
147
+ assert realize(List[_U], var_mapping) == list[int]
148
+ else:
149
+ assert realize(List[_U], var_mapping) == List[int]
135
150
 
136
151
 
137
152
  def test_intersect_signatures_basic():
@@ -24,7 +24,7 @@ def extract_linenums(text: str) -> List[int]:
24
24
 
25
25
  def find_examples() -> Iterable[Path]:
26
26
  examples_dir = pathlib.Path(os.path.realpath(__file__)).parent
27
- for path in sorted(examples_dir.glob("**/*.py")):
27
+ for path in sorted(examples_dir.glob("*/**/*.py")):
28
28
  if path.stem != "__init__":
29
29
  yield path
30
30
 
crosshair/main.py CHANGED
@@ -860,16 +860,24 @@ def check(
860
860
  if isinstance(entities, int):
861
861
  return entities
862
862
  full_options = DEFAULT_OPTIONS.overlay(report_verbose=False).overlay(options)
863
- for entity in entities:
864
- debug("Check ", getattr(entity, "__name__", str(entity)))
865
- for message in run_checkables(analyze_any(entity, options)):
866
- line = describe_message(message, full_options)
867
- if line is None:
868
- continue
869
- stdout.write(line + "\n")
870
- debug("Traceback for output message:\n", message.traceback)
871
- if message.state > MessageType.PRE_UNSAT:
872
- any_problems = True
863
+ checkables = [c for e in entities for c in analyze_any(e, options)]
864
+ if not checkables:
865
+ extra_help = ""
866
+ if full_options.analysis_kind == [AnalysisKind.asserts]:
867
+ extra_help = "\nHINT: Ensure that your functions to analyze lead with assert statements."
868
+ print(
869
+ "WARNING: Targets found, but contain no checkable functions." + extra_help,
870
+ file=stderr,
871
+ )
872
+
873
+ for message in run_checkables(checkables):
874
+ line = describe_message(message, full_options)
875
+ if line is None:
876
+ continue
877
+ stdout.write(line + "\n")
878
+ debug("Traceback for output message:\n", message.traceback)
879
+ if message.state > MessageType.PRE_UNSAT:
880
+ any_problems = True
873
881
  return 1 if any_problems else 0
874
882
 
875
883
 
crosshair/main_test.py CHANGED
@@ -251,19 +251,28 @@ def test_no_args_prints_usage(root):
251
251
  assert re.search(r"^usage", out)
252
252
 
253
253
 
254
- def DISABLE_TODO_test_assert_mode_e2e(root):
254
+ def test_assert_mode_e2e(root, capsys: pytest.CaptureFixture[str]):
255
255
  simplefs(root, ASSERT_BASED_FOO)
256
- try:
257
- sys.stdout = io.StringIO()
258
- exitcode = unwalled_main(["check", root / "foo.py", "--analysis_kind=asserts"])
259
- finally:
260
- out = sys.stdout.getvalue()
261
- sys.stdout = sys.__stdout__
262
- assert exitcode == 1
256
+ exitcode = unwalled_main(["check", str(root / "foo.py"), "--analysis_kind=asserts"])
257
+ (out, err) = capsys.readouterr()
258
+ assert err == ""
263
259
  assert re.search(
264
- r"foo.py\:8\: error\: AssertionError\: when calling foofn\(x \= 100\)", out
260
+ r"foo.py\:8\: error\: AssertionError\: when calling foofn\(100\)", out
265
261
  )
266
262
  assert len([ls for ls in out.split("\n") if ls]) == 1
263
+ assert exitcode == 1
264
+
265
+
266
+ def test_assert_without_checkable(root, capsys: pytest.CaptureFixture[str]):
267
+ simplefs(root, SIMPLE_FOO)
268
+ exitcode = unwalled_main(["check", str(root / "foo.py"), "--analysis_kind=asserts"])
269
+ (out, err) = capsys.readouterr()
270
+ assert (
271
+ err
272
+ == "WARNING: Targets found, but contain no checkable functions.\nHINT: Ensure that your functions to analyze lead with assert statements.\n"
273
+ )
274
+ assert out == ""
275
+ assert exitcode == 0
267
276
 
268
277
 
269
278
  def test_directives(root):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: crosshair-tool
3
- Version: 0.0.93
3
+ Version: 0.0.94
4
4
  Summary: Analyze Python code for correctness using symbolic execution.
5
5
  Home-page: https://github.com/pschanely/CrossHair
6
6
  Author: Phillip Schanely
@@ -1,5 +1,5 @@
1
- _crosshair_tracers.cp38-win_amd64.pyd,sha256=ImLwMEdrR1ETEdC7t2rV3B6BZjE-PQRF3TleI_PeqY4,21504
2
- crosshair/__init__.py,sha256=aNQs81VDq95_ZF8wWBUtdIO4BNRcGH-CkBCuKIy37dE,978
1
+ _crosshair_tracers.cp38-win_amd64.pyd,sha256=7C95w1Ny1Cet9t7ombZ8B9oAcI3GFRrJemox7DuuEjs,21504
2
+ crosshair/__init__.py,sha256=MJjBwGp2rylUig86jpTmjum-iQ-meS0EmJhfAr30dLo,978
3
3
  crosshair/__main__.py,sha256=i4pjsZlXvtieQHJTEB0sF3e40qJjLoOm1z5rm-u70Uo,260
4
4
  crosshair/_mark_stacks.h,sha256=IImygydFK9qethf41gUZDjySHR3WLXs-YsqWCHK9UFg,29468
5
5
  crosshair/_preliminaries_test.py,sha256=klkzKGpyyVDGctCXdvq1xyXbGa4PRnXda1jfgE-7LLY,522
@@ -16,14 +16,14 @@ crosshair/condition_parser_test.py,sha256=kosW60A4HnBBT3sOHxWCl_cixpbO1kmsjgNuNU
16
16
  crosshair/conftest.py,sha256=JjUauvXnjERszuS46iskuBRHBx-0uHacwKHeQ-gEQ2c,683
17
17
  crosshair/copyext.py,sha256=_SRnS6UrUFl2-CHl8uRIOq-Y0MKYNQTFK132S3Ru34A,5044
18
18
  crosshair/copyext_test.py,sha256=VSIoVeqAf18g2RNuLTbyNWJiMBgzHeab7LNX1KHCWZU,2182
19
- crosshair/core.py,sha256=bUkWzbyhEvk24_UJ7tYo489ccq-Q6V0Pnpj4aY165qg,65497
19
+ crosshair/core.py,sha256=1aAptxDoCv-hYIxl5USINEE6eJsKKctoZf0k9wpX9v8,65928
20
20
  crosshair/core_and_libs.py,sha256=U9GDCBE9Ecxy7T7bmJT7IYiQTdY1C8qbcoIoMMocu5U,4112
21
21
  crosshair/core_regestered_types_test.py,sha256=3o1GrtjCEWSW-paPp5-yVdE2K1_ZIviGCff7KVZ0VS0,2181
22
- crosshair/core_test.py,sha256=bHpq_OcUsVWFWGnsCUX4AEM22vLfoCzCsPaEnsbAzYc,33490
22
+ crosshair/core_test.py,sha256=2rKU1rUrUPeYLQ-I0UbddUx9henGAacRbmeeMd-2K14,34323
23
23
  crosshair/diff_behavior.py,sha256=2T11J2Hk35Qp3RRp5ALtXyTgAl3v0W3KDNR_mSec-D4,11567
24
24
  crosshair/diff_behavior_test.py,sha256=TUmqPOj_Qij8a7NMLFYt0IskL5Q_CdDLD5pnxnomuJ0,7505
25
- crosshair/dynamic_typing.py,sha256=YDh0e73AnWyPjwjPXbjO4vSqpgIhYaV5AURpRe2AkXg,12323
26
- crosshair/dynamic_typing_test.py,sha256=szfUa9zLFVMv1YiuJvrC9-ZMZnlS36tqJ373MGXVkAA,5673
25
+ crosshair/dynamic_typing.py,sha256=UspjP89YmX5CzkMrXrPRl6DL4eqmsuHMQv-zTpq4JcQ,13104
26
+ crosshair/dynamic_typing_test.py,sha256=4z9s6j-u2oQqlrzFx9Mc2Mc0RBPGiCZ2mDqP0F4IFVA,6117
27
27
  crosshair/enforce.py,sha256=lIeDeqavEa06tVMlIk5ScibVGS04yHZ3xIpkTPK5QQw,10291
28
28
  crosshair/enforce_test.py,sha256=CvofUxa_Y-np5vhlBcjsrZ2CkpxNFbjv5U-rH027pw4,4847
29
29
  crosshair/fnutil.py,sha256=Fe77jLudjf7X_fNLExLoMTFElQWQ3wCpA_MC06JaOKk,13515
@@ -31,8 +31,8 @@ crosshair/fnutil_test.py,sha256=I-jFcROrNFUs7xSGrLcGJk_cX8014g5h8ItwPSFpvLY,2264
31
31
  crosshair/fuzz_core_test.py,sha256=wWILaE5cpxfiRl89WgCWMpNIGS8BnWcQmgartQYCCJ8,17411
32
32
  crosshair/lsp_server.py,sha256=Kl6z-Nudt2ZkzV0ojfzvGGa3cukXLOYKTCHYJUxzrRk,8920
33
33
  crosshair/lsp_server_test.py,sha256=yHp7JtJLpF2G049lwhNlgAYXnVM88CtsudVVHVY7Hs0,999
34
- crosshair/main.py,sha256=Dibj8nGZeNe010vCU0j1v-h8IhcUJyyED_dVKQZaIj0,35341
35
- crosshair/main_test.py,sha256=zzNANuPZd9SWr15jSWfHVsGFKTWMlyREgnxKojJj-eo,14958
34
+ crosshair/main.py,sha256=2kiGrmjNeLYkgzPnrc-zyfWPJqCi2km_SSZ0IDhm-_Q,35630
35
+ crosshair/main_test.py,sha256=BQvSEE_hkyIOW_n9-SIkG29k1ZFuB6j8LgftVvNmXAU,15377
36
36
  crosshair/objectproxy.py,sha256=qYPVvH3EVUmh7GI9-73mfmOTzcTH_gyn5DhK44hp8KI,9286
37
37
  crosshair/objectproxy_test.py,sha256=P5N28U5l9ngozqLr2EgtVOII3PS3fB2dOOPc9LLt8Zo,590
38
38
  crosshair/opcode_intercept.py,sha256=RGcwx4f5-KKjY2C3Do4mBm4S8rEpn6nWtOQvaSKQnoM,22453
@@ -72,7 +72,7 @@ crosshair/watcher_test.py,sha256=TCOdXmdGZ3NJ59X_w7SRVqiJY-BL2tUqyXK-3ql1d6s,287
72
72
  crosshair/z3util.py,sha256=_NcVbYhvSt24vhkpiXdEh4o2VRSIjb4g8Xpq49sJsGg,1835
73
73
  crosshair/z3util_test.py,sha256=9_6fhpTphEQlg4QY29bGzN0KxfktsT8wYveNgbfqueg,184
74
74
  crosshair/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
75
- crosshair/examples/check_examples_test.py,sha256=Gu5NzNZN0aOBdJzujXLBuxSwag79CjplEhqp6Rdn9zs,4205
75
+ crosshair/examples/check_examples_test.py,sha256=0xoBSAVt3cLJdmvPVvSXsN8Szot16kPyihWG8iToi_4,4207
76
76
  crosshair/examples/PEP316/__init__.py,sha256=39eVIMt1avfS9HXte7nzP9LbVlFo97Q4-YL1CQXM1JM,35
77
77
  crosshair/examples/PEP316/bugs_detected/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
78
78
  crosshair/examples/PEP316/bugs_detected/getattr_magic.py,sha256=PyaKiAVHnlaPTEpaupKmGQcyK24HGiq1eKU2t-mHJFo,335
@@ -167,9 +167,9 @@ crosshair/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
167
167
  crosshair/tools/check_help_in_doc.py,sha256=An-2EJ0_Xr-Szo431AoEgJafoFWwnPl8HoT4bi86dd8,8499
168
168
  crosshair/tools/check_init_and_setup_coincide.py,sha256=f4TvPg1Q3C_BQYtGgPfY_fqxo_ZTeU7QCy7WwQjaIlA,3621
169
169
  crosshair/tools/generate_demo_table.py,sha256=qm4ZUXjUBKkVZ3bVVK9h6dJMDKYme8zMl-7at_aG7b0,3958
170
- crosshair_tool-0.0.93.dist-info/LICENSE,sha256=qQLSJN48eqvalILMr3uzkg0p74FtK7WSwkux-0twy-s,4552
171
- crosshair_tool-0.0.93.dist-info/METADATA,sha256=HvJ77a1X42cdi05tJu51AbGfjqc4v_eIWd2qr38idAY,6692
172
- crosshair_tool-0.0.93.dist-info/WHEEL,sha256=2M046GvC9RLU1f1TWyM-2sB7cRKLhAC7ucAFK8l8f24,99
173
- crosshair_tool-0.0.93.dist-info/entry_points.txt,sha256=u5FIPVn1jqn4Kzg5K_iNnbP6L4hQw5FWjQ0UMezG2VE,96
174
- crosshair_tool-0.0.93.dist-info/top_level.txt,sha256=2jLWtM-BWg_ZYNbNfrcds0HFZD62a6J7ZIbcgcQrRk4,29
175
- crosshair_tool-0.0.93.dist-info/RECORD,,
170
+ crosshair_tool-0.0.94.dist-info/LICENSE,sha256=qQLSJN48eqvalILMr3uzkg0p74FtK7WSwkux-0twy-s,4552
171
+ crosshair_tool-0.0.94.dist-info/METADATA,sha256=6GgnwAUAPfZUjDFHIy9ZB4AK0wW8HGhRipShZjFZB9Q,6692
172
+ crosshair_tool-0.0.94.dist-info/WHEEL,sha256=2M046GvC9RLU1f1TWyM-2sB7cRKLhAC7ucAFK8l8f24,99
173
+ crosshair_tool-0.0.94.dist-info/entry_points.txt,sha256=u5FIPVn1jqn4Kzg5K_iNnbP6L4hQw5FWjQ0UMezG2VE,96
174
+ crosshair_tool-0.0.94.dist-info/top_level.txt,sha256=2jLWtM-BWg_ZYNbNfrcds0HFZD62a6J7ZIbcgcQrRk4,29
175
+ crosshair_tool-0.0.94.dist-info/RECORD,,