Skip to content

Commit 2bd6256

Browse files
committed
Sure
1 parent e493ea4 commit 2bd6256

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/basilisp/core.lpy

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6904,7 +6904,7 @@
69046904
(dissoc! m k)))
69056905
(transient (.- self -proxy-mappings)))
69066906
(persistent!))]
6907-
(set! (.- self -proxy-mappings) updated-mappings)
6907+
(. self (_set_proxy_mappings updated-mappings))
69086908
nil))
69096909
"_proxy_mappings" nil}
69106910

@@ -6996,7 +6996,6 @@
69966996
(. proxy (_update-proxy-mappings mappings))
69976997
proxy)))
69986998

6999-
;; TODO: kwargs on supertypes
70006999
;; TODO: check interface/superclass method membership
70017000
(defmacro proxy
70027001
"Create a new proxy class instance.
@@ -7025,26 +7024,39 @@
70257024
([arg1] ...)
70267025
([arg1 & others] ...))
70277026

7027+
.. note::
7028+
7029+
Proxy override methods can be defined with Python keyword argument support since
7030+
they are just standard Basilisp functions. See :ref:`basilisp_functions_with_kwargs`
7031+
for more information.
7032+
70287033
.. warning::
70297034

70307035
The ``proxy`` macro does not verify that the provided override implementations
70317036
arities match those of the method being overridden."
70327037
[class-and-interfaces args & fs]
70337038
(let [formatted-single (fn [method-name [arg-vec & body]]
7034-
[(munge method-name)
7035-
(apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
7039+
(apply list
7040+
'fn
7041+
method-name
7042+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7043+
body))
70367044
formatted-multi (fn [method-name & arities]
7037-
[(munge method-name)
7038-
(apply list
7039-
'fn
7040-
method-name
7041-
(map (fn [[arg-vec & body]]
7042-
(apply list (vec (concat ['this] arg-vec)) body))
7043-
arities))])
7044-
methods (map (fn [[method-name & body]]
7045-
(if (vector? (first body))
7046-
(formatted-single method-name body)
7047-
(apply formatted-multi method-name body)))
7045+
(apply list
7046+
'fn
7047+
method-name
7048+
(map (fn [[arg-vec & body]]
7049+
(apply list
7050+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7051+
body))
7052+
arities)))
7053+
methods (map (fn [[method-name & body :as form]]
7054+
[(munge method-name)
7055+
(with-meta
7056+
(if (vector? (first body))
7057+
(formatted-single method-name body)
7058+
(apply formatted-multi method-name body))
7059+
(meta form))])
70487060
fs)
70497061
method-map (reduce* (fn [m [method-name method]]
70507062
(if-let [existing-method (get m method-name)]

tests/basilisp/test_proxies.lpy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
(deftest proxy-test
3939
(testing "disallows duplicate method overrides"
40-
(proxy [Describable] []
41-
(describe-me [] "I'm a proxy")
42-
(describe-me [] "Proxy")))
40+
(is (thrown? basilisp.lang.compiler/CompilerException
41+
(eval '(proxy [Describable] []
42+
(describe-me [] "I'm a proxy")
43+
(describe-me [] "Proxy"))))))
4344

4445
(testing "multi-arity interface methods"
4546
(let [p (proxy [ConcreteToString] [1]

0 commit comments

Comments
 (0)