Skip to content
This repository was archived by the owner on Apr 21, 2023. It is now read-only.

Commit b9aa387

Browse files
authored
Merge pull request pvieito#42 from philipturner/patch-2
Add support for functions that don't return
2 parents 350b921 + 0c73938 commit b9aa387

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

PythonKit/Python.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,14 +1550,27 @@ public struct PythonFunction {
15501550
return try fn(argumentsAsTuple[0])
15511551
}
15521552
}
1553+
1554+
public init(_ fn: @escaping (PythonObject) throws -> Void) {
1555+
function = PyFunction { argumentsAsTuple in
1556+
try fn(argumentsAsTuple[0])
1557+
return Python.None
1558+
}
1559+
}
15531560

15541561
/// For cases where the Swift function should accept more (or less) than one parameter, accept an ordered array of all arguments instead
15551562
public init(_ fn: @escaping ([PythonObject]) throws -> PythonConvertible) {
15561563
function = PyFunction { argumentsAsTuple in
15571564
return try fn(argumentsAsTuple.map { $0 })
15581565
}
15591566
}
1560-
1567+
1568+
public init(_ fn: @escaping ([PythonObject]) throws -> Void) {
1569+
function = PyFunction { argumentsAsTuple in
1570+
try fn(argumentsAsTuple.map { $0 })
1571+
return Python.None
1572+
}
1573+
}
15611574
}
15621575

15631576
extension PythonFunction : PythonConvertible {

0 commit comments

Comments
 (0)