diff --git a/package-lock.json b/package-lock.json index 3af2b2b4..9e3958a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "write-your-python-program", - "version": "1.1.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "write-your-python-program", - "version": "1.1.0", + "version": "1.2.1", "license": "See license in LICENSE", "dependencies": { "@types/node": "^18.11.13", diff --git a/python/fileTests b/python/fileTests index 3279f251..c88d21de 100755 --- a/python/fileTests +++ b/python/fileTests @@ -288,6 +288,7 @@ checkWithOutputAux yes 1 test-data/testLiteral1.py checkWithOutputAux yes 0 test-data/testForwardTypeInRecord.py checkWithOutputAux yes 0 test-data/testForwardTypeInRecord2.py checkWithOutputAux yes 0 test-data/testUnionOfUnion.py +checkWithOutputAux yes 1 test-data/testRecordTypes.py function is_min_version() { diff --git a/python/src/runner.py b/python/src/runner.py index 0b089255..8e2f514e 100644 --- a/python/src/runner.py +++ b/python/src/runner.py @@ -254,7 +254,7 @@ def __init__(self, mod, properlyImported): if name and name[0] != '_': d[name] = getattr(mod, name) -def prepareLib(onlyCheckRunnable): +def prepareLib(onlyCheckRunnable, enableTypeChecking): libDefs = None mod = INSTALLED_MODULE_NAME verbose('Attempting to import ' + mod) @@ -262,6 +262,7 @@ def prepareLib(onlyCheckRunnable): libDefs = Lib(wypp, True) verbose('Successfully imported module ' + mod + ' from file ' + wypp.__file__) libDefs.initModule(enableChecks=not onlyCheckRunnable, + enableTypeChecking=enableTypeChecking, quiet=onlyCheckRunnable) return libDefs @@ -534,7 +535,7 @@ def main(globals, argList=None): if not args.checkRunnable and (not args.quiet or args.verbose): printWelcomeString(fileToRun, version, useUntypy=args.checkTypes) - libDefs = prepareLib(onlyCheckRunnable=args.checkRunnable) + libDefs = prepareLib(onlyCheckRunnable=args.checkRunnable, enableTypeChecking=args.checkTypes) globals['__name__'] = '__wypp__' sys.modules['__wypp__'] = sys.modules['__main__'] diff --git a/python/src/writeYourProgram.py b/python/src/writeYourProgram.py index b92d09eb..ce22370f 100644 --- a/python/src/writeYourProgram.py +++ b/python/src/writeYourProgram.py @@ -141,7 +141,10 @@ def _setattr(obj, k, v): def record(cls=None, mutable=False): def wrap(cls): newCls = dataclasses.dataclass(cls, frozen=not mutable) - return _patchDataClass(newCls, mutable) + if _typeCheckingEnabled: + return _patchDataClass(newCls, mutable) + else: + return newCls # See if we're being called as @record or @record(). if cls is None: # We're called with parens. @@ -155,6 +158,7 @@ def wrap(cls): _die = False def setDieOnCheckFailures(b): + global _die _die = b def _dieOnCheckFailures(): @@ -162,10 +166,12 @@ def _dieOnCheckFailures(): _testCount = {'total': 0, 'failing': 0} _checksEnabled = True +_typeCheckingEnabled = False -def initModule(enableChecks=True, quiet=False): - global _checksEnabled +def initModule(enableChecks=True, enableTypeChecking=True, quiet=False): + global _checksEnabled, _typeCheckingEnabled _checksEnabled = enableChecks + _typeCheckingEnabled = enableTypeChecking resetTestCount() def resetTestCount(): diff --git a/python/test-data/testRecordTypes.err b/python/test-data/testRecordTypes.err new file mode 100644 index 00000000..84554590 --- /dev/null +++ b/python/test-data/testRecordTypes.err @@ -0,0 +1,12 @@ +Traceback (most recent call last): + File "test-data/testRecordTypes.py", line 8, in + p = Point(1, '5') +WyppTypeError: got value of wrong type +given: '5' +expected: value of type int + +context: record constructor Point(x: int, y: int) -> Self + ^^^ +declared at: test-data/testRecordTypes.py:4 +caused by: test-data/testRecordTypes.py:8 + | p = Point(1, '5') diff --git a/python/test-data/testRecordTypes.err-3.12 b/python/test-data/testRecordTypes.err-3.12 new file mode 100644 index 00000000..37fbf43c --- /dev/null +++ b/python/test-data/testRecordTypes.err-3.12 @@ -0,0 +1,12 @@ +Traceback (most recent call last): + File "test-data/testRecordTypes.py", line 8, in + p = Point(1, '5') +WyppTypeError: got value of wrong type +given: '5' +expected: value of type int + +context: record constructor Point(x: int, y: int) -> Self + ^^^ +declared at: test-data/testRecordTypes.py:3 +caused by: test-data/testRecordTypes.py:8 + | p = Point(1, '5') diff --git a/python/test-data/testRecordTypes.out b/python/test-data/testRecordTypes.out new file mode 100644 index 00000000..e69de29b diff --git a/python/test-data/testRecordTypes.py b/python/test-data/testRecordTypes.py new file mode 100644 index 00000000..a9b58a5c --- /dev/null +++ b/python/test-data/testRecordTypes.py @@ -0,0 +1,8 @@ +from wypp import * + +@record +class Point: + x: int + y: int + +p = Point(1, '5') diff --git a/python/tests/testRecord.py b/python/tests/testRecord.py index 237b87e5..20a8b3db 100644 --- a/python/tests/testRecord.py +++ b/python/tests/testRecord.py @@ -4,6 +4,7 @@ import traceback import dataclasses +initModule() setDieOnCheckFailures(True) @record diff --git a/src/programflow-visualization/constants.ts b/src/programflow-visualization/constants.ts index 96d36c1d..476c0451 100644 --- a/src/programflow-visualization/constants.ts +++ b/src/programflow-visualization/constants.ts @@ -6,6 +6,13 @@ export namespace Variables { } export const nextLineExecuteHighlightType = vscode.window.createTextEditorDecorationType({ - backgroundColor: 'rgba(255, 255, 0, 0.25)', // Yellow + borderWidth: '1px', + borderStyle: 'solid', isWholeLine: true, + borderColor: 'rgb(40, 40, 40)', + backgroundColor: 'rgba(248, 248, 181, 0.75)', + dark: { + borderColor: 'rgb(215, 215, 215)', + backgroundColor: 'rgba(75, 75, 24, 0.75)', + } });