No TypeError from multi-arity defn returning None
This commit is contained in:
parent
e8ffd41202
commit
432d560310
1
NEWS
1
NEWS
@ -25,6 +25,7 @@ Changes from 0.13.0
|
|||||||
* Fixed a bug where REPL history wasn't saved if you quit the REPL with
|
* Fixed a bug where REPL history wasn't saved if you quit the REPL with
|
||||||
`(quit)` or `(exit)`
|
`(quit)` or `(exit)`
|
||||||
* `exec` now works under Python 2
|
* `exec` now works under Python 2
|
||||||
|
* No TypeError from multi-arity defn returning values evaluating to None
|
||||||
|
|
||||||
Changes from 0.12.1
|
Changes from 0.12.1
|
||||||
|
|
||||||
|
@ -26,13 +26,13 @@
|
|||||||
(.issubset (frozenset (.keys kwargs)) com)))
|
(.issubset (frozenset (.keys kwargs)) com)))
|
||||||
|
|
||||||
__call__ (fn [self &rest args &kwargs kwargs]
|
__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__))]
|
(for [[i f] (.items (get self._fns self.f.__module__ self.f.__name__))]
|
||||||
(when (.fn? self i args kwargs)
|
(when (.fn? self i args kwargs)
|
||||||
(setv output (f #* args #** kwargs))
|
(setv func f)
|
||||||
(break)))
|
(break)))
|
||||||
(if output
|
(if func
|
||||||
output
|
(func #* args #** kwargs)
|
||||||
(raise (TypeError "No matching functions with this signature"))))])
|
(raise (TypeError "No matching functions with this signature"))))])
|
||||||
|
|
||||||
(defn multi-decorator [dispatch-fn]
|
(defn multi-decorator [dispatch-fn]
|
||||||
|
@ -26,6 +26,22 @@
|
|||||||
(assert (= (fun "a" "b") "a b"))
|
(assert (= (fun "a" "b") "a b"))
|
||||||
(assert (= (fun "a" "b" "c") "a b c")))
|
(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 []
|
(defn test-basic-dispatch []
|
||||||
"NATIVE: Test basic dispatch"
|
"NATIVE: Test basic dispatch"
|
||||||
|
Loading…
Reference in New Issue
Block a user