Skip to content

Commit 7d55f9a

Browse files
authored
Merge pull request #191 from skogsbaer/sw/fixes-2025-10-29
Improve startup
2 parents d03404b + 45e0142 commit 7d55f9a

18 files changed

+243
-54
lines changed

python/code/wypp/ansi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def color(s, color):
2323
return color + s + RESET
2424

2525
def green(s):
26-
return color(s, GREEN)
26+
return color(s, GREEN + BOLD)
2727

2828
def red(s):
2929
return color(s, RED + BOLD)

python/code/wypp/interactive.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@
88
from constants import *
99
from myLogging import *
1010
from exceptionHandler import handleCurrentException
11-
import i18n
12-
13-
def prepareInteractive(reset=True):
14-
print()
15-
if reset:
16-
if os.name == 'nt':
17-
# clear the terminal
18-
os.system('cls')
19-
else:
20-
# On linux & mac use ANSI Sequence for this
21-
print('\033[2J\033[H')
22-
2311

2412
HISTORY_SIZE = 1000
2513

@@ -48,11 +36,12 @@ def enterInteractive(userDefs: dict, checkTypes: bool, loadingFailed: bool):
4836
historyFile = getHistoryFilePath()
4937
try:
5038
import readline
39+
except:
40+
readline = None
41+
if readline:
5142
readline.parse_and_bind('tab: complete')
5243
if historyFile and os.path.exists(historyFile):
5344
readline.read_history_file(historyFile)
54-
except:
55-
pass
5645
try:
5746
consoleClass(locals=userDefs).interact(banner="", exitmsg='')
5847
finally:

python/code/wypp/records.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ def init(enableTypeChecking=True):
1717
global _typeCheckingEnabled
1818
_typeCheckingEnabled = enableTypeChecking
1919

20-
def _collectDataClassAttributes(cls):
21-
result = dict()
22-
for c in cls.mro():
23-
if hasattr(c, '__kind') and c.__kind == 'record' and hasattr(c, '__annotations__'):
24-
result = c.__annotations__ | result
25-
return result
26-
2720
def _checkRecordAttr(cls: typing.Any,
2821
ns: myTypeguard.Namespaces,
2922
name: str,
@@ -48,11 +41,8 @@ def _patchDataClass(cls, mutable: bool, ns: myTypeguard.Namespaces):
4841
fieldNames = [f.name for f in dataclasses.fields(cls)]
4942
setattr(cls, EQ_ATTRS_ATTR, fieldNames)
5043

51-
if hasattr(cls, '__annotations__'):
52-
# add annotions for type checked constructor.
53-
cls.__kind = 'record'
54-
cls.__init__.__annotations__ = _collectDataClassAttributes(cls)
55-
cls.__init__ = typecheck.wrapTypecheckRecordConstructor(cls, ns)
44+
cls.__kind = 'record'
45+
cls.__init__ = typecheck.wrapTypecheckRecordConstructor(cls, ns)
5646

5747
if mutable:
5848
# prevent new fields being added

python/code/wypp/runner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def pythonVersionOk(v):
3333
import runCode
3434
import exceptionHandler
3535
import cmdlineArgs
36-
36+
import ansi
3737

3838
def printWelcomeString(file, version, doTypecheck):
3939
cwd = os.getcwd() + "/"
@@ -44,8 +44,10 @@ def printWelcomeString(file, version, doTypecheck):
4444
tycheck = ''
4545
if not doTypecheck:
4646
tycheck = ', no typechecking'
47-
printStderr(i18n.tr('=== WELCOME to ') + '"Write Your Python Program" ' +
48-
'(%sPython %s, %s%s) ===' % (versionStr, pythonVersion, file, tycheck))
47+
msg = i18n.tr('=== WELCOME to ') + '"Write Your Python Program" ' + \
48+
'(%sPython %s, %s%s) ===' % (versionStr, pythonVersion, file, tycheck)
49+
fullMsg = (10 * '\n') + ansi.green(msg) + '\n'
50+
printStderr(fullMsg)
4951

5052
def main(globals, argList=None):
5153
(args, restArgs) = cmdlineArgs.parseCmdlineArgs(argList)
@@ -70,8 +72,6 @@ def main(globals, argList=None):
7072

7173
isInteractive = args.interactive
7274
version = versionMod.readVersion()
73-
if isInteractive:
74-
interactive.prepareInteractive(reset=not args.noClear)
7575

7676
if fileToRun is None:
7777
return

python/file-test-data/basics/recursive2_ok.err

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Kinzig
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
from wypp import *
3+
4+
# Ein Flussabschnitt ist entweder
5+
# - ein Bach mit Namen und Quelle, oder
6+
# - ein Zusammenfluss eines Haupt- und Nebenflussabschnitts an einem bestimmten Ort.
7+
8+
@record
9+
class Creek:
10+
origin: str
11+
name: str
12+
13+
@record
14+
class Confluence:
15+
location: str
16+
mainStem: RiverSection
17+
tributary: RiverSection
18+
19+
type RiverSection = Union[Creek, Confluence]
20+
21+
kinzig1 = Creek('Loßburg', 'Kinzig')
22+
gutach = Creek('Schönwald', 'Gutach')
23+
kinzig2 = Confluence('Hausach', kinzig1, gutach)
24+
schutter1 = Creek('Schweighausen', 'Schutter')
25+
heidengraben = Creek('Lahr', 'Heidengraben')
26+
schutter2 = Confluence('Lahr', schutter1, heidengraben)
27+
kinzig3 = Confluence('Kehl', kinzig2, schutter2)
28+
29+
# Name eines Flussabschnitts bestimmen
30+
# Eingabe: den Flussabschnitt (Typ: RiverSection)
31+
# Ergebnis: der Name (Typ: str)
32+
def riverName(r: RiverSection) -> str:
33+
if isinstance(r, Creek):
34+
return r.name
35+
elif isinstance(r, Confluence):
36+
return riverName(r.mainStem)
37+
38+
print(riverName(kinzig3))

python/file-test-data/basics/recursive_ok.err

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Kinzig
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from wypp import *
2+
3+
# Ein Flussabschnitt ist entweder
4+
# - ein Bach mit Namen und Quelle, oder
5+
# - ein Zusammenfluss eines Haupt- und Nebenflussabschnitts an einem bestimmten Ort.
6+
7+
@record
8+
class Creek:
9+
origin: str
10+
name: str
11+
12+
@record
13+
class Confluence:
14+
location: str
15+
mainStem: RiverSection
16+
tributary: RiverSection
17+
18+
type RiverSection = Union[Creek, Confluence]
19+
20+
kinzig1 = Creek('Loßburg', 'Kinzig')
21+
gutach = Creek('Schönwald', 'Gutach')
22+
kinzig2 = Confluence('Hausach', kinzig1, gutach)
23+
schutter1 = Creek('Schweighausen', 'Schutter')
24+
heidengraben = Creek('Lahr', 'Heidengraben')
25+
schutter2 = Confluence('Lahr', schutter1, heidengraben)
26+
kinzig3 = Confluence('Kehl', kinzig2, schutter2)
27+
28+
# Name eines Flussabschnitts bestimmen
29+
# Eingabe: den Flussabschnitt (Typ: RiverSection)
30+
# Ergebnis: der Name (Typ: str)
31+
def riverName(r: RiverSection) -> str:
32+
if isinstance(r, Creek):
33+
return r.name
34+
elif isinstance(r, Confluence):
35+
return riverName(r.mainStem)
36+
37+
print(riverName(kinzig3))

0 commit comments

Comments
 (0)