Skip to content

Commit fe14fa4

Browse files
Fixed '__add__'-Function. (hopefully)
1 parent 70cf7a0 commit fe14fa4

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

microps/wrappers/wrapper.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def __init__(self, v, engine):
3131
def __add__(self, o):
3232
left = self._val
3333
right = unwrap(o)
34-
# Attempt to convert strings containing numbers to float
34+
# If either operand is a string, concatenate as strings (JS-like)
35+
if isinstance(left, str) or isinstance(right, str):
36+
return self.__class__(str(left) + str(right), self._engine)
37+
# Attempt to convert to float otherwise
3538
for idx, val in enumerate([left, right]):
3639
if isinstance(val, str):
3740
try:
@@ -40,7 +43,7 @@ def __add__(self, o):
4043
else:
4144
right = float(right)
4245
except ValueError:
43-
pass # If not convertible, leave as is
46+
pass
4447
if isinstance(left, (int, float)) and isinstance(right, (int, float)):
4548
return self.__class__(_core.add(left, right), self._engine)
4649
raise TypeError(f"Cannot add {type(left).__name__} and {type(right).__name__}")

0 commit comments

Comments
 (0)