|
6944 | 6944 | "Generate a proxy class with the given bases." |
6945 | 6945 | [bases] |
6946 | 6946 | (let [methods (apply hash-map (mapcat proxy-base-methods bases)) |
| 6947 | + method-names (set (map munge (keys methods))) |
6947 | 6948 | base-methods {"__init__" (fn __init__ [self proxy-mappings & args] |
6948 | 6949 | (apply (.- (python/super (.- self __class__) self) __init__) args) |
6949 | | - (set! (.- self -proxy-mappings) proxy-mappings) |
| 6950 | + (. self (_set_proxy_mappings proxy-mappings)) |
6950 | 6951 | nil) |
6951 | 6952 | "_get_proxy_mappings" (fn _get_proxy_mappings [self] |
6952 | 6953 | (.- self -proxy-mappings)) |
6953 | 6954 | "_set_proxy_mappings" (fn _set_proxy_mappings [self proxy-mappings] |
| 6955 | + (let [provided-methods (set (keys proxy-mappings))] |
| 6956 | + (when-not (.issubset provided-methods method-names) |
| 6957 | + (throw |
| 6958 | + (ex-info "Proxy override methods must correspond to methods on the declared supertypes" |
| 6959 | + {:expected method-names |
| 6960 | + :given provided-methods |
| 6961 | + :diff (.difference provided-methods method-names)})))) |
6954 | 6962 | (set! (.- self -proxy-mappings) proxy-mappings) |
6955 | 6963 | nil) |
6956 | 6964 | "_update_proxy_mappings" (fn _update_proxy_mappings [self proxy-mappings] |
|
6967 | 6975 |
|
6968 | 6976 | ;; Remove Python ``object`` from the bases if it is present to avoid errors |
6969 | 6977 | ;; about creating a consistent MRO for the given bases |
6970 | | - proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6971 | | - #_(doseq [[method-name method] methods] |
6972 | | - (println method-name method)) |
| 6978 | + proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6973 | 6979 | (python/type (basilisp.lang.util/genname "Proxy") |
6974 | 6980 | (python/tuple proxy-bases) |
6975 | 6981 | (python/dict (merge methods base-methods))))) |
|
7053 | 7059 | (. proxy (_update-proxy-mappings mappings)) |
7054 | 7060 | proxy))) |
7055 | 7061 |
|
7056 | | -;; TODO: check interface/superclass method membership |
7057 | 7062 | (defmacro proxy |
7058 | 7063 | "Create a new proxy class instance. |
7059 | 7064 |
|
|
7124 | 7129 | (assoc m method-name method))) |
7125 | 7130 | {} |
7126 | 7131 | methods)] |
7127 | | - #_(println methods) |
7128 | 7132 | `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7129 | 7133 |
|
7130 | 7134 | (defmacro proxy-super |
|
0 commit comments