|
6993 | 6993 | "Generate a proxy class with the given bases." |
6994 | 6994 | [bases] |
6995 | 6995 | (let [methods (apply hash-map (mapcat proxy-base-methods bases)) |
| 6996 | + method-names (set (map munge (keys methods))) |
6996 | 6997 | base-methods {"__init__" (fn __init__ [self proxy-mappings & args] |
6997 | 6998 | (apply (.- (python/super (.- self __class__) self) __init__) args) |
6998 | | - (set! (.- self -proxy-mappings) proxy-mappings) |
| 6999 | + (. self (_set_proxy_mappings proxy-mappings)) |
6999 | 7000 | nil) |
7000 | 7001 | "_get_proxy_mappings" (fn _get_proxy_mappings [self] |
7001 | 7002 | (.- self -proxy-mappings)) |
7002 | 7003 | "_set_proxy_mappings" (fn _set_proxy_mappings [self proxy-mappings] |
| 7004 | + (let [provided-methods (set (keys proxy-mappings))] |
| 7005 | + (when-not (.issubset provided-methods method-names) |
| 7006 | + (throw |
| 7007 | + (ex-info "Proxy override methods must correspond to methods on the declared supertypes" |
| 7008 | + {:expected method-names |
| 7009 | + :given provided-methods |
| 7010 | + :diff (.difference provided-methods method-names)})))) |
7003 | 7011 | (set! (.- self -proxy-mappings) proxy-mappings) |
7004 | 7012 | nil) |
7005 | 7013 | "_update_proxy_mappings" (fn _update_proxy_mappings [self proxy-mappings] |
|
7016 | 7024 |
|
7017 | 7025 | ;; Remove Python ``object`` from the bases if it is present to avoid errors |
7018 | 7026 | ;; about creating a consistent MRO for the given bases |
7019 | | - proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
7020 | | - #_(doseq [[method-name method] methods] |
7021 | | - (println method-name method)) |
| 7027 | + proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
7022 | 7028 | (python/type (basilisp.lang.util/genname "Proxy") |
7023 | 7029 | (python/tuple proxy-bases) |
7024 | 7030 | (python/dict (merge methods base-methods))))) |
|
7102 | 7108 | (. proxy (_update-proxy-mappings mappings)) |
7103 | 7109 | proxy))) |
7104 | 7110 |
|
7105 | | -;; TODO: check interface/superclass method membership |
7106 | 7111 | (defmacro proxy |
7107 | 7112 | "Create a new proxy class instance. |
7108 | 7113 |
|
|
7173 | 7178 | (assoc m method-name method))) |
7174 | 7179 | {} |
7175 | 7180 | methods)] |
7176 | | - #_(println methods) |
7177 | 7181 | `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7178 | 7182 |
|
7179 | 7183 | (defmacro proxy-super |
|
0 commit comments