No TypeError from multi-arity defn returning None

This commit is contained in:
David Schaefer 2017-08-04 17:08:41 +02:00
parent e8ffd41202
commit 432d560310
3 changed files with 21 additions and 4 deletions

1
NEWS
View File

@ -25,6 +25,7 @@ Changes from 0.13.0
* Fixed a bug where REPL history wasn't saved if you quit the REPL with
`(quit)` or `(exit)`
* `exec` now works under Python 2
* No TypeError from multi-arity defn returning values evaluating to None
Changes from 0.12.1

View File

@ -26,13 +26,13 @@
(.issubset (frozenset (.keys kwargs)) com)))
__call__ (fn [self &rest args &kwargs kwargs]
(setv output None)
(setv func None)
(for [[i f] (.items (get self._fns self.f.__module__ self.f.__name__))]
(when (.fn? self i args kwargs)
(setv output (f #* args #** kwargs))
(setv func f)
(break)))
(if output
output
(if func
(func #* args #** kwargs)
(raise (TypeError "No matching functions with this signature"))))])
(defn multi-decorator [dispatch-fn]

View File

@ -26,6 +26,22 @@
(assert (= (fun "a" "b") "a b"))
(assert (= (fun "a" "b" "c") "a b c")))
(defn test-different-signatures-defn []
"NATIVE: Test defn with different signatures"
(defn fun
([] "")
([a] "a")
([a b] "a b"))
(assert (= (fun) ""))
(assert (= (fun "a") "a"))
(assert (= (fun "a" "b") "a b"))
(try
(do
(fun "a" "b" "c")
(assert False))
(except [e Exception]
(assert (isinstance e TypeError)))))
(defn test-basic-dispatch []
"NATIVE: Test basic dispatch"