diff --git a/src/libpython_clj2/python/bridge_as_python.clj b/src/libpython_clj2/python/bridge_as_python.clj index 676e792..9754c08 100644 --- a/src/libpython_clj2/python/bridge_as_python.clj +++ b/src/libpython_clj2/python/bridge_as_python.clj @@ -122,7 +122,7 @@ "__setitem__" (as-tuple-instance-fn #(.put (self->map %1) (py-base/as-jvm %2) %3)) "__delitem__" (as-tuple-instance-fn #(.remove (self->map %1) (py-base/as-jvm %2))) "__hash__" (as-tuple-instance-fn #(.hashCode (self->map %1))) - "__iter__" (as-tuple-instance-fn #(.iterator ^Iterable (keys (self->map %1)))) + "__iter__" (as-tuple-instance-fn #(.iterator ^Iterable (or (keys (self->map %1)) []))) "__len__" (as-tuple-instance-fn #(.size (self->map %1))) "__str__" (as-tuple-instance-fn #(.toString (self->map %1))) "clear" (as-tuple-instance-fn #(.clear (self->map %1))) diff --git a/test/libpython_clj2/python_test.clj b/test/libpython_clj2/python_test.clj index bc50c6d..7f1b270 100644 --- a/test/libpython_clj2/python_test.clj +++ b/test/libpython_clj2/python_test.clj @@ -7,7 +7,8 @@ [tech.v3.datatype.functional :as dfn] [tech.v3.datatype.ffi :as dt-ffi] [tech.v3.tensor :as dtt] - [clojure.test :refer :all]) + [clojure.test :refer :all] + libpython-clj2.python.bridge-as-python) (:import [java.io StringWriter] [java.util Map List] [tech.v3.datatype.ffi Pointer])) @@ -422,6 +423,10 @@ class Foo: (is (= [5 2] (py/->jvm (py/get-attr pp "shape")))))) +(deftest iter-should-not-npe + ;; credit Carsten Behring + (is (true? (boolean (py. (libpython-clj2.python.bridge-as-python/map-as-python {}) __iter__))))) + (comment (require '[libpython-clj.require :refer [require-python]])
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: