crosshair-tool 0.0.99__cp312-cp312-macosx_10_13_x86_64.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.
- _crosshair_tracers.cpython-312-darwin.so +0 -0
- crosshair/__init__.py +42 -0
- crosshair/__main__.py +8 -0
- crosshair/_mark_stacks.h +790 -0
- crosshair/_preliminaries_test.py +18 -0
- crosshair/_tracers.h +94 -0
- crosshair/_tracers_pycompat.h +522 -0
- crosshair/_tracers_test.py +138 -0
- crosshair/abcstring.py +245 -0
- crosshair/auditwall.py +190 -0
- crosshair/auditwall_test.py +77 -0
- crosshair/codeconfig.py +113 -0
- crosshair/codeconfig_test.py +117 -0
- crosshair/condition_parser.py +1237 -0
- crosshair/condition_parser_test.py +497 -0
- crosshair/conftest.py +30 -0
- crosshair/copyext.py +155 -0
- crosshair/copyext_test.py +84 -0
- crosshair/core.py +1763 -0
- crosshair/core_and_libs.py +149 -0
- crosshair/core_regestered_types_test.py +82 -0
- crosshair/core_test.py +1316 -0
- crosshair/diff_behavior.py +314 -0
- crosshair/diff_behavior_test.py +261 -0
- crosshair/dynamic_typing.py +346 -0
- crosshair/dynamic_typing_test.py +210 -0
- crosshair/enforce.py +282 -0
- crosshair/enforce_test.py +182 -0
- crosshair/examples/PEP316/__init__.py +1 -0
- crosshair/examples/PEP316/bugs_detected/__init__.py +0 -0
- crosshair/examples/PEP316/bugs_detected/getattr_magic.py +16 -0
- crosshair/examples/PEP316/bugs_detected/hash_consistent_with_equals.py +31 -0
- crosshair/examples/PEP316/bugs_detected/shopping_cart.py +24 -0
- crosshair/examples/PEP316/bugs_detected/showcase.py +39 -0
- crosshair/examples/PEP316/correct_code/__init__.py +0 -0
- crosshair/examples/PEP316/correct_code/arith.py +60 -0
- crosshair/examples/PEP316/correct_code/chess.py +77 -0
- crosshair/examples/PEP316/correct_code/nesting_inference.py +17 -0
- crosshair/examples/PEP316/correct_code/numpy_examples.py +132 -0
- crosshair/examples/PEP316/correct_code/rolling_average.py +35 -0
- crosshair/examples/PEP316/correct_code/showcase.py +104 -0
- crosshair/examples/__init__.py +0 -0
- crosshair/examples/check_examples_test.py +146 -0
- crosshair/examples/deal/__init__.py +1 -0
- crosshair/examples/icontract/__init__.py +1 -0
- crosshair/examples/icontract/bugs_detected/__init__.py +0 -0
- crosshair/examples/icontract/bugs_detected/showcase.py +41 -0
- crosshair/examples/icontract/bugs_detected/wrong_sign.py +8 -0
- crosshair/examples/icontract/correct_code/__init__.py +0 -0
- crosshair/examples/icontract/correct_code/arith.py +51 -0
- crosshair/examples/icontract/correct_code/showcase.py +94 -0
- crosshair/fnutil.py +391 -0
- crosshair/fnutil_test.py +75 -0
- crosshair/fuzz_core_test.py +516 -0
- crosshair/libimpl/__init__.py +0 -0
- crosshair/libimpl/arraylib.py +161 -0
- crosshair/libimpl/binascii_ch_test.py +30 -0
- crosshair/libimpl/binascii_test.py +67 -0
- crosshair/libimpl/binasciilib.py +150 -0
- crosshair/libimpl/bisectlib_test.py +23 -0
- crosshair/libimpl/builtinslib.py +5228 -0
- crosshair/libimpl/builtinslib_ch_test.py +1191 -0
- crosshair/libimpl/builtinslib_test.py +3735 -0
- crosshair/libimpl/codecslib.py +86 -0
- crosshair/libimpl/codecslib_test.py +86 -0
- crosshair/libimpl/collectionslib.py +264 -0
- crosshair/libimpl/collectionslib_ch_test.py +252 -0
- crosshair/libimpl/collectionslib_test.py +332 -0
- crosshair/libimpl/copylib.py +23 -0
- crosshair/libimpl/copylib_test.py +18 -0
- crosshair/libimpl/datetimelib.py +2559 -0
- crosshair/libimpl/datetimelib_ch_test.py +354 -0
- crosshair/libimpl/datetimelib_test.py +112 -0
- crosshair/libimpl/decimallib.py +5257 -0
- crosshair/libimpl/decimallib_ch_test.py +78 -0
- crosshair/libimpl/decimallib_test.py +76 -0
- crosshair/libimpl/encodings/__init__.py +23 -0
- crosshair/libimpl/encodings/_encutil.py +187 -0
- crosshair/libimpl/encodings/ascii.py +44 -0
- crosshair/libimpl/encodings/latin_1.py +40 -0
- crosshair/libimpl/encodings/utf_8.py +93 -0
- crosshair/libimpl/encodings_ch_test.py +83 -0
- crosshair/libimpl/fractionlib.py +16 -0
- crosshair/libimpl/fractionlib_test.py +80 -0
- crosshair/libimpl/functoolslib.py +34 -0
- crosshair/libimpl/functoolslib_test.py +56 -0
- crosshair/libimpl/hashliblib.py +30 -0
- crosshair/libimpl/hashliblib_test.py +18 -0
- crosshair/libimpl/heapqlib.py +47 -0
- crosshair/libimpl/heapqlib_test.py +21 -0
- crosshair/libimpl/importliblib.py +18 -0
- crosshair/libimpl/importliblib_test.py +38 -0
- crosshair/libimpl/iolib.py +216 -0
- crosshair/libimpl/iolib_ch_test.py +128 -0
- crosshair/libimpl/iolib_test.py +19 -0
- crosshair/libimpl/ipaddresslib.py +8 -0
- crosshair/libimpl/itertoolslib.py +44 -0
- crosshair/libimpl/itertoolslib_test.py +44 -0
- crosshair/libimpl/jsonlib.py +984 -0
- crosshair/libimpl/jsonlib_ch_test.py +42 -0
- crosshair/libimpl/jsonlib_test.py +51 -0
- crosshair/libimpl/mathlib.py +179 -0
- crosshair/libimpl/mathlib_ch_test.py +44 -0
- crosshair/libimpl/mathlib_test.py +67 -0
- crosshair/libimpl/oslib.py +7 -0
- crosshair/libimpl/pathliblib_test.py +10 -0
- crosshair/libimpl/randomlib.py +178 -0
- crosshair/libimpl/randomlib_test.py +120 -0
- crosshair/libimpl/relib.py +846 -0
- crosshair/libimpl/relib_ch_test.py +169 -0
- crosshair/libimpl/relib_test.py +493 -0
- crosshair/libimpl/timelib.py +72 -0
- crosshair/libimpl/timelib_test.py +82 -0
- crosshair/libimpl/typeslib.py +15 -0
- crosshair/libimpl/typeslib_test.py +36 -0
- crosshair/libimpl/unicodedatalib.py +75 -0
- crosshair/libimpl/unicodedatalib_test.py +42 -0
- crosshair/libimpl/urlliblib.py +23 -0
- crosshair/libimpl/urlliblib_test.py +19 -0
- crosshair/libimpl/weakreflib.py +13 -0
- crosshair/libimpl/weakreflib_test.py +69 -0
- crosshair/libimpl/zliblib.py +15 -0
- crosshair/libimpl/zliblib_test.py +13 -0
- crosshair/lsp_server.py +261 -0
- crosshair/lsp_server_test.py +30 -0
- crosshair/main.py +973 -0
- crosshair/main_test.py +543 -0
- crosshair/objectproxy.py +376 -0
- crosshair/objectproxy_test.py +41 -0
- crosshair/opcode_intercept.py +601 -0
- crosshair/opcode_intercept_test.py +304 -0
- crosshair/options.py +218 -0
- crosshair/options_test.py +10 -0
- crosshair/patch_equivalence_test.py +75 -0
- crosshair/path_cover.py +209 -0
- crosshair/path_cover_test.py +138 -0
- crosshair/path_search.py +161 -0
- crosshair/path_search_test.py +52 -0
- crosshair/pathing_oracle.py +271 -0
- crosshair/pathing_oracle_test.py +21 -0
- crosshair/pure_importer.py +27 -0
- crosshair/pure_importer_test.py +16 -0
- crosshair/py.typed +0 -0
- crosshair/register_contract.py +273 -0
- crosshair/register_contract_test.py +190 -0
- crosshair/simplestructs.py +1165 -0
- crosshair/simplestructs_test.py +283 -0
- crosshair/smtlib.py +24 -0
- crosshair/smtlib_test.py +14 -0
- crosshair/statespace.py +1199 -0
- crosshair/statespace_test.py +108 -0
- crosshair/stubs_parser.py +352 -0
- crosshair/stubs_parser_test.py +43 -0
- crosshair/test_util.py +329 -0
- crosshair/test_util_test.py +26 -0
- crosshair/tools/__init__.py +0 -0
- crosshair/tools/check_help_in_doc.py +264 -0
- crosshair/tools/check_init_and_setup_coincide.py +119 -0
- crosshair/tools/generate_demo_table.py +127 -0
- crosshair/tracers.py +544 -0
- crosshair/tracers_test.py +154 -0
- crosshair/type_repo.py +151 -0
- crosshair/unicode_categories.py +589 -0
- crosshair/unicode_categories_test.py +27 -0
- crosshair/util.py +741 -0
- crosshair/util_test.py +173 -0
- crosshair/watcher.py +307 -0
- crosshair/watcher_test.py +107 -0
- crosshair/z3util.py +76 -0
- crosshair/z3util_test.py +11 -0
- crosshair_tool-0.0.99.dist-info/METADATA +144 -0
- crosshair_tool-0.0.99.dist-info/RECORD +176 -0
- crosshair_tool-0.0.99.dist-info/WHEEL +6 -0
- crosshair_tool-0.0.99.dist-info/entry_points.txt +3 -0
- crosshair_tool-0.0.99.dist-info/licenses/LICENSE +93 -0
- crosshair_tool-0.0.99.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"""Register all type handlers and exports core functionality."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
from packaging import version
|
|
7
|
+
|
|
8
|
+
from crosshair import opcode_intercept
|
|
9
|
+
|
|
10
|
+
# These imports are just for exporting functionality:
|
|
11
|
+
from crosshair.core import (
|
|
12
|
+
AnalysisMessage,
|
|
13
|
+
MessageType,
|
|
14
|
+
_reset_all_registrations,
|
|
15
|
+
analyze_any,
|
|
16
|
+
analyze_class,
|
|
17
|
+
analyze_function,
|
|
18
|
+
analyze_module,
|
|
19
|
+
proxy_for_type,
|
|
20
|
+
run_checkables,
|
|
21
|
+
standalone_statespace,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
# Modules with registrations:
|
|
25
|
+
from crosshair.libimpl import (
|
|
26
|
+
arraylib,
|
|
27
|
+
binasciilib,
|
|
28
|
+
builtinslib,
|
|
29
|
+
codecslib,
|
|
30
|
+
collectionslib,
|
|
31
|
+
copylib,
|
|
32
|
+
datetimelib,
|
|
33
|
+
decimallib,
|
|
34
|
+
fractionlib,
|
|
35
|
+
functoolslib,
|
|
36
|
+
hashliblib,
|
|
37
|
+
heapqlib,
|
|
38
|
+
importliblib,
|
|
39
|
+
iolib,
|
|
40
|
+
ipaddresslib,
|
|
41
|
+
itertoolslib,
|
|
42
|
+
jsonlib,
|
|
43
|
+
mathlib,
|
|
44
|
+
oslib,
|
|
45
|
+
randomlib,
|
|
46
|
+
relib,
|
|
47
|
+
timelib,
|
|
48
|
+
typeslib,
|
|
49
|
+
unicodedatalib,
|
|
50
|
+
urlliblib,
|
|
51
|
+
weakreflib,
|
|
52
|
+
zliblib,
|
|
53
|
+
)
|
|
54
|
+
from crosshair.options import AnalysisKind, AnalysisOptions
|
|
55
|
+
from crosshair.tracers import NoTracing, ResumedTracing
|
|
56
|
+
from crosshair.util import debug
|
|
57
|
+
|
|
58
|
+
if sys.version_info < (3, 10):
|
|
59
|
+
from importlib_metadata import entry_points
|
|
60
|
+
else:
|
|
61
|
+
from importlib.metadata import entry_points
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
installed_plugins: List[str] = [] # We record these for diagnostic purposes
|
|
65
|
+
__all__ = [
|
|
66
|
+
"analyze_function",
|
|
67
|
+
"analyze_any",
|
|
68
|
+
"analyze_class",
|
|
69
|
+
"analyze_module",
|
|
70
|
+
"run_checkables",
|
|
71
|
+
"proxy_for_type",
|
|
72
|
+
"standalone_statespace",
|
|
73
|
+
"AnalysisMessage",
|
|
74
|
+
"MessageType",
|
|
75
|
+
"AnalysisKind",
|
|
76
|
+
"AnalysisOptions",
|
|
77
|
+
"NoTracing",
|
|
78
|
+
"ResumedTracing",
|
|
79
|
+
"debug",
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _make_registrations():
|
|
84
|
+
_reset_all_registrations()
|
|
85
|
+
arraylib.make_registrations()
|
|
86
|
+
binasciilib.make_registrations()
|
|
87
|
+
builtinslib.make_registrations()
|
|
88
|
+
codecslib.make_registrations()
|
|
89
|
+
collectionslib.make_registrations()
|
|
90
|
+
copylib.make_registrations()
|
|
91
|
+
datetimelib.make_registrations()
|
|
92
|
+
decimallib.make_registrations()
|
|
93
|
+
functoolslib.make_registrations()
|
|
94
|
+
fractionlib.make_registrations()
|
|
95
|
+
hashliblib.make_registrations()
|
|
96
|
+
heapqlib.make_registrations()
|
|
97
|
+
jsonlib.make_registrations()
|
|
98
|
+
importliblib.make_registrations()
|
|
99
|
+
iolib.make_registrations()
|
|
100
|
+
ipaddresslib.make_registrations()
|
|
101
|
+
itertoolslib.make_registrations()
|
|
102
|
+
mathlib.make_registrations()
|
|
103
|
+
oslib.make_registrations()
|
|
104
|
+
randomlib.make_registrations()
|
|
105
|
+
relib.make_registrations()
|
|
106
|
+
timelib.make_registrations()
|
|
107
|
+
typeslib.make_registrations()
|
|
108
|
+
unicodedatalib.make_registrations()
|
|
109
|
+
urlliblib.make_registrations()
|
|
110
|
+
opcode_intercept.make_registrations()
|
|
111
|
+
weakreflib.make_registrations()
|
|
112
|
+
zliblib.make_registrations()
|
|
113
|
+
|
|
114
|
+
plugin_entries = entry_points(group="crosshair.plugin")
|
|
115
|
+
for plugin_entry in plugin_entries:
|
|
116
|
+
installed_plugins.append(plugin_entry.name)
|
|
117
|
+
plugin_entry.load()
|
|
118
|
+
|
|
119
|
+
# We monkey patch icontract below to prevent it from enforcing contracts.
|
|
120
|
+
# (we want to control how and when they run)
|
|
121
|
+
# TODO: consider a better home for this code
|
|
122
|
+
try:
|
|
123
|
+
import icontract # type: ignore
|
|
124
|
+
|
|
125
|
+
if version.parse(icontract.__version__) < version.parse("2.4.0"):
|
|
126
|
+
raise Exception("CrossHair requires icontract version >= 2.4.0")
|
|
127
|
+
|
|
128
|
+
icontract._checkers._assert_invariant = lambda *a, **kw: None
|
|
129
|
+
icontract._checkers._assert_preconditions = lambda *a, **kw: None
|
|
130
|
+
icontract._checkers._assert_postconditions = lambda *a, **kw: None
|
|
131
|
+
except ImportError:
|
|
132
|
+
pass
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
import deal # type: ignore
|
|
136
|
+
|
|
137
|
+
deal_version = version.parse(deal.__version__)
|
|
138
|
+
if deal_version < version.parse("4.13.0"):
|
|
139
|
+
raise Exception("CrossHair requires deal version >= 4.13.0")
|
|
140
|
+
if deal_version < version.parse("4.21.2"):
|
|
141
|
+
deal.disable()
|
|
142
|
+
else:
|
|
143
|
+
# deal >= 4.21.2 throws runtime warnings.
|
|
144
|
+
deal.disable(warn=False)
|
|
145
|
+
except ImportError:
|
|
146
|
+
pass
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
_make_registrations()
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import re
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import (
|
|
5
|
+
Any,
|
|
6
|
+
BinaryIO,
|
|
7
|
+
Callable,
|
|
8
|
+
Final,
|
|
9
|
+
List,
|
|
10
|
+
NamedTuple,
|
|
11
|
+
NoReturn,
|
|
12
|
+
SupportsBytes,
|
|
13
|
+
SupportsComplex,
|
|
14
|
+
Union,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
import pytest # type: ignore
|
|
18
|
+
import typing_inspect # type: ignore
|
|
19
|
+
|
|
20
|
+
from crosshair.core import _SIMPLE_PROXIES, proxy_for_type
|
|
21
|
+
from crosshair.dynamic_typing import origin_of
|
|
22
|
+
from crosshair.tracers import ResumedTracing
|
|
23
|
+
from crosshair.util import CrosshairUnsupported, debug, name_of_type
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
Tests that the builtin and standard library types behave like their
|
|
27
|
+
counterparts.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
possible_args = [
|
|
32
|
+
(),
|
|
33
|
+
(Any,),
|
|
34
|
+
(Any, Any),
|
|
35
|
+
(Any, Any, Any),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
untested_types = {
|
|
39
|
+
# These types won't check at runtime:
|
|
40
|
+
Union,
|
|
41
|
+
NoReturn,
|
|
42
|
+
Final,
|
|
43
|
+
BinaryIO,
|
|
44
|
+
SupportsBytes,
|
|
45
|
+
SupportsComplex,
|
|
46
|
+
# Callable actually works ok but can throw IgnoreAttempt
|
|
47
|
+
collections.abc.Callable,
|
|
48
|
+
# TODO: make a symbolic NamedTuple that intercepts attribute access:
|
|
49
|
+
NamedTuple,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
comparisons: List = []
|
|
54
|
+
for typ, creator in _SIMPLE_PROXIES.items():
|
|
55
|
+
if typ in untested_types:
|
|
56
|
+
continue
|
|
57
|
+
name = name_of_type(typ)
|
|
58
|
+
comparisons.append(pytest.param(typ, creator, id=name))
|
|
59
|
+
if typing_inspect.is_generic_type(typ) and hasattr(typ, "__getitem__"):
|
|
60
|
+
for nargs in range(1, 3):
|
|
61
|
+
type_args = tuple([Any for _ in range(nargs)])
|
|
62
|
+
try:
|
|
63
|
+
typ_paramed = typ.__getitem__(type_args)
|
|
64
|
+
except TypeError:
|
|
65
|
+
pass
|
|
66
|
+
else:
|
|
67
|
+
comparisons.append(
|
|
68
|
+
pytest.param(typ_paramed, creator, id=name + "_with_{nargs}_args")
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@pytest.mark.parametrize("typ,creator", comparisons)
|
|
73
|
+
def test_patch(typ: type, creator: Callable, space):
|
|
74
|
+
debug("Patch test:", typ, creator)
|
|
75
|
+
try:
|
|
76
|
+
proxy = proxy_for_type(typ, "x")
|
|
77
|
+
except CrosshairUnsupported:
|
|
78
|
+
debug("Ignored pass - CrossHair explicitly does not support this type")
|
|
79
|
+
return
|
|
80
|
+
origin = origin_of(typ)
|
|
81
|
+
with ResumedTracing():
|
|
82
|
+
assert isinstance(proxy, origin)
|