Skip to content

Commit 3090f18

Browse files
committed
Sure
1 parent 406ee59 commit 3090f18

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
@@ -6961,7 +6961,7 @@
69616961
(dissoc! m k)))
69626962
(transient (.- self -proxy-mappings)))
69636963
(persistent!))]
6964-
(set! (.- self -proxy-mappings) updated-mappings)
6964+
(. self (_set_proxy_mappings updated-mappings))
69656965
nil))
69666966
"_proxy_mappings" nil}
69676967

@@ -7053,7 +7053,6 @@
70537053
(. proxy (_update-proxy-mappings mappings))
70547054
proxy)))
70557055

7056-
;; TODO: kwargs on supertypes
70577056
;; TODO: check interface/superclass method membership
70587057
(defmacro proxy
70597058
"Create a new proxy class instance.
@@ -7082,26 +7081,39 @@
70827081
([arg1] ...)
70837082
([arg1 & others] ...))
70847083

7084+
.. note::
7085+
7086+
Proxy override methods can be defined with Python keyword argument support since
7087+
they are just standard Basilisp functions. See :ref:`basilisp_functions_with_kwargs`
7088+
for more information.
7089+
70857090
.. warning::
70867091

70877092
The ``proxy`` macro does not verify that the provided override implementations
70887093
arities match those of the method being overridden."
70897094
[class-and-interfaces args & fs]
70907095
(let [formatted-single (fn [method-name [arg-vec & body]]
7091-
[(munge method-name)
7092-
(apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
7096+
(apply list
7097+
'fn
7098+
method-name
7099+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7100+
body))
70937101
formatted-multi (fn [method-name & arities]
7094-
[(munge method-name)
7095-
(apply list
7096-
'fn
7097-
method-name
7098-
(map (fn [[arg-vec & body]]
7099-
(apply list (vec (concat ['this] arg-vec)) body))
7100-
arities))])
7101-
methods (map (fn [[method-name & body]]
7102-
(if (vector? (first body))
7103-
(formatted-single method-name body)
7104-
(apply formatted-multi method-name body)))
7102+
(apply list
7103+
'fn
7104+
method-name
7105+
(map (fn [[arg-vec & body]]
7106+
(apply list
7107+
(with-meta (vec (concat ['this] arg-vec)) (meta arg-vec))
7108+
body))
7109+
arities)))
7110+
methods (map (fn [[method-name & body :as form]]
7111+
[(munge method-name)
7112+
(with-meta
7113+
(if (vector? (first body))
7114+
(formatted-single method-name body)
7115+
(apply formatted-multi method-name body))
7116+
(meta form))])
71057117
fs)
71067118
method-map (reduce* (fn [m [method-name method]]
71077119
(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)