Skip to content

Commit c71d674

Browse files
committed
Fixes #126
1 parent 3b0c79f commit c71d674

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Time for a ChangeLog!
22

3+
## 2.00-beta-19
4+
* [issue 126](https://github.com/clj-python/libpython-clj/issues/126) - Python maps sometimes fail to destructure.
5+
36
## 2.00-beta-18
47
* Additional fix for 162 to allow booleans to be considered primitives and be output inline.
58
* Experimental fix for [issue 164](https://github.com/clj-python/libpython-clj/issues/164) - Unsigned int64 fails with

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{:paths ["src"]
22
:deps {org.clojure/clojure {:mvn/version "1.10.2" :scope "provided"}
3-
cnuernber/dtype-next {:mvn/version "7.13"}
3+
cnuernber/dtype-next {:mvn/version "8.00"}
44
net.java.dev.jna/jna {:mvn/version "5.7.0"}
55
org.clojure/data.json {:mvn/version "1.0.0"}}
66

src/libpython_clj2/python/bridge_as_jvm.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@
310310
iterator-seq
311311
set)))
312312
(get [this obj-key]
313-
(py-call "__getitem__" obj-key))
313+
;;Specifically return nil to match java map expectations
314+
;;and thus allow destructuring.
315+
(when (py-call "__contains__" obj-key)
316+
(py-call "__getitem__" obj-key)))
314317
(getOrDefault [item obj-key obj-default-value]
315318
(if (.containsKey item obj-key)
316319
(.get item obj-key)

test/libpython_clj2/python_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ class Foo:
407407
(is (= 8 (py/call-attr py-data "__len__")))))
408408

409409

410+
(deftest python-as-jvm-destructuring
411+
(let [py-dict (py/->python {:a 1})
412+
jvm-py-dict (py/as-jvm py-dict)
413+
{:keys [a b]} jvm-py-dict]
414+
(is (nil? b))))
415+
416+
410417
(comment
411418
(require '[libpython-clj.require :refer [require-python]])
412419

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy