Skip to content

Commit 2c20c56

Browse files
authored
Merge branch 'master' into scroll-to-stack-end
2 parents e296bae + 4c0be3c commit 2c20c56

File tree

16 files changed

+188
-344
lines changed

16 files changed

+188
-344
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/fileTests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ checkWithOutputAux yes 1 test-data/testLiteral1.py
288288
checkWithOutputAux yes 0 test-data/testForwardTypeInRecord.py
289289
checkWithOutputAux yes 0 test-data/testForwardTypeInRecord2.py
290290
checkWithOutputAux yes 0 test-data/testUnionOfUnion.py
291+
checkWithOutputAux yes 1 test-data/testRecordTypes.py
291292

292293
function is_min_version()
293294
{

python/src/runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ def __init__(self, mod, properlyImported):
254254
if name and name[0] != '_':
255255
d[name] = getattr(mod, name)
256256

257-
def prepareLib(onlyCheckRunnable):
257+
def prepareLib(onlyCheckRunnable, enableTypeChecking):
258258
libDefs = None
259259
mod = INSTALLED_MODULE_NAME
260260
verbose('Attempting to import ' + mod)
261261
wypp = importlib.import_module(mod)
262262
libDefs = Lib(wypp, True)
263263
verbose('Successfully imported module ' + mod + ' from file ' + wypp.__file__)
264264
libDefs.initModule(enableChecks=not onlyCheckRunnable,
265+
enableTypeChecking=enableTypeChecking,
265266
quiet=onlyCheckRunnable)
266267
return libDefs
267268

@@ -534,7 +535,7 @@ def main(globals, argList=None):
534535
if not args.checkRunnable and (not args.quiet or args.verbose):
535536
printWelcomeString(fileToRun, version, useUntypy=args.checkTypes)
536537

537-
libDefs = prepareLib(onlyCheckRunnable=args.checkRunnable)
538+
libDefs = prepareLib(onlyCheckRunnable=args.checkRunnable, enableTypeChecking=args.checkTypes)
538539

539540
globals['__name__'] = '__wypp__'
540541
sys.modules['__wypp__'] = sys.modules['__main__']

python/src/writeYourProgram.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ def _setattr(obj, k, v):
141141
def record(cls=None, mutable=False):
142142
def wrap(cls):
143143
newCls = dataclasses.dataclass(cls, frozen=not mutable)
144-
return _patchDataClass(newCls, mutable)
144+
if _typeCheckingEnabled:
145+
return _patchDataClass(newCls, mutable)
146+
else:
147+
return newCls
145148
# See if we're being called as @record or @record().
146149
if cls is None:
147150
# We're called with parens.
@@ -155,17 +158,20 @@ def wrap(cls):
155158
_die = False
156159

157160
def setDieOnCheckFailures(b):
161+
global _die
158162
_die = b
159163

160164
def _dieOnCheckFailures():
161165
return _die
162166

163167
_testCount = {'total': 0, 'failing': 0}
164168
_checksEnabled = True
169+
_typeCheckingEnabled = False
165170

166-
def initModule(enableChecks=True, quiet=False):
167-
global _checksEnabled
171+
def initModule(enableChecks=True, enableTypeChecking=True, quiet=False):
172+
global _checksEnabled, _typeCheckingEnabled
168173
_checksEnabled = enableChecks
174+
_typeCheckingEnabled = enableTypeChecking
169175
resetTestCount()
170176

171177
def resetTestCount():

python/test-data/testRecordTypes.err

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Traceback (most recent call last):
2+
File "test-data/testRecordTypes.py", line 8, in <module>
3+
p = Point(1, '5')
4+
WyppTypeError: got value of wrong type
5+
given: '5'
6+
expected: value of type int
7+
8+
context: record constructor Point(x: int, y: int) -> Self
9+
^^^
10+
declared at: test-data/testRecordTypes.py:4
11+
caused by: test-data/testRecordTypes.py:8
12+
| p = Point(1, '5')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Traceback (most recent call last):
2+
File "test-data/testRecordTypes.py", line 8, in <module>
3+
p = Point(1, '5')
4+
WyppTypeError: got value of wrong type
5+
given: '5'
6+
expected: value of type int
7+
8+
context: record constructor Point(x: int, y: int) -> Self
9+
^^^
10+
declared at: test-data/testRecordTypes.py:3
11+
caused by: test-data/testRecordTypes.py:8
12+
| p = Point(1, '5')

python/test-data/testRecordTypes.out

Whitespace-only changes.

python/test-data/testRecordTypes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from wypp import *
2+
3+
@record
4+
class Point:
5+
x: int
6+
y: int
7+
8+
p = Point(1, '5')

python/tests/testRecord.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import traceback
55
import dataclasses
66

7+
initModule()
78
setDieOnCheckFailures(True)
89

910
@record

pytrace-generator/main.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def eprint(*args, **kwargs):
1616
print(*args, file=sys.stderr, **kwargs)
1717

1818
type_name_regex = re.compile("<class '(?:__main__\\.)?(.*)'>")
19+
function_str_regex = re.compile(r"^(<function .+) at .+>")
1920
import_regex = re.compile(r"^(?:[^'\"]+\s)?import[\s*]")
2021

2122
# Frame objects:
@@ -26,10 +27,11 @@ def eprint(*args, **kwargs):
2627
float: "float",
2728
bool: "bool",
2829
str: "str",
29-
type(None): "none"
30+
type(None): "none",
31+
type: "type",
32+
types.FunctionType: "function"
3033
}
3134
HEAP_TYPES = {
32-
type: "type",
3335
list: "list",
3436
tuple: "tuple",
3537
dict: "dict",
@@ -112,6 +114,18 @@ def format(self):
112114
"type": self.type_str,
113115
"value": self.value
114116
}
117+
if type(d["value"]) == type:
118+
type_name = str(d["value"])
119+
search_result = type_name_regex.search(type_name)
120+
if search_result is not None:
121+
type_name = f"<class '{search_result.group(1)}'>"
122+
d["value"] = type_name
123+
elif inspect.isfunction(d["value"]):
124+
function_desc = str(d["value"])
125+
search_result = function_str_regex.search(function_desc)
126+
if search_result is not None:
127+
function_desc = f"{search_result.group(1)}>"
128+
d["value"] = function_desc
115129
if self.variable_name is not None:
116130
d["name"] = self.variable_name
117131
return d
@@ -200,11 +214,6 @@ def store(self, address, value):
200214
stored_value[key_id] = prim_value
201215
if prim_value.is_ref():
202216
inner_values.append(v)
203-
elif value_type == type:
204-
stored_value = str(value)
205-
search_result = type_name_regex.search(stored_value)
206-
if search_result is not None:
207-
stored_value = f"<class '{search_result.group(1)}'>"
208217
elif inspect.isgenerator(value):
209218
stored_value = {}
210219
else:

0 commit comments

Comments
 (0)