|
6821 | 6821 | "Generate a proxy class with the given bases." |
6822 | 6822 | [bases] |
6823 | 6823 | (let [methods (apply hash-map (mapcat proxy-base-methods bases)) |
| 6824 | + method-names (set (map munge (keys methods))) |
6824 | 6825 | base-methods {"__init__" (fn __init__ [self proxy-mappings & args] |
6825 | 6826 | (apply (.- (python/super (.- self __class__) self) __init__) args) |
6826 | | - (set! (.- self -proxy-mappings) proxy-mappings) |
| 6827 | + (. self (_set_proxy_mappings proxy-mappings)) |
6827 | 6828 | nil) |
6828 | 6829 | "_get_proxy_mappings" (fn _get_proxy_mappings [self] |
6829 | 6830 | (.- self -proxy-mappings)) |
6830 | 6831 | "_set_proxy_mappings" (fn _set_proxy_mappings [self proxy-mappings] |
| 6832 | + (let [provided-methods (set (keys proxy-mappings))] |
| 6833 | + (when-not (.issubset provided-methods method-names) |
| 6834 | + (throw |
| 6835 | + (ex-info "Proxy override methods must correspond to methods on the declared supertypes" |
| 6836 | + {:expected method-names |
| 6837 | + :given provided-methods |
| 6838 | + :diff (.difference provided-methods method-names)})))) |
6831 | 6839 | (set! (.- self -proxy-mappings) proxy-mappings) |
6832 | 6840 | nil) |
6833 | 6841 | "_update_proxy_mappings" (fn _update_proxy_mappings [self proxy-mappings] |
|
6844 | 6852 |
|
6845 | 6853 | ;; Remove Python ``object`` from the bases if it is present to avoid errors |
6846 | 6854 | ;; about creating a consistent MRO for the given bases |
6847 | | - proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6848 | | - #_(doseq [[method-name method] methods] |
6849 | | - (println method-name method)) |
| 6855 | + proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6850 | 6856 | (python/type (basilisp.lang.util/genname "Proxy") |
6851 | 6857 | (python/tuple proxy-bases) |
6852 | 6858 | (python/dict (merge methods base-methods))))) |
|
6930 | 6936 | (. proxy (_update-proxy-mappings mappings)) |
6931 | 6937 | proxy))) |
6932 | 6938 |
|
6933 | | -;; TODO: check interface/superclass method membership |
6934 | 6939 | (defmacro proxy |
6935 | 6940 | "Create a new proxy class instance. |
6936 | 6941 |
|
|
7001 | 7006 | (assoc m method-name method))) |
7002 | 7007 | {} |
7003 | 7008 | methods)] |
7004 | | - #_(println methods) |
7005 | 7009 | `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7006 | 7010 |
|
7007 | 7011 | (defmacro proxy-super |
|
0 commit comments