|
6853 | 6853 | "Generate a proxy class with the given bases." |
6854 | 6854 | [bases] |
6855 | 6855 | (let [methods (apply hash-map (mapcat proxy-base-methods bases)) |
| 6856 | + method-names (set (map munge (keys methods))) |
6856 | 6857 | base-methods {"__init__" (fn __init__ [self proxy-mappings & args] |
6857 | 6858 | (apply (.- (python/super (.- self __class__) self) __init__) args) |
6858 | | - (set! (.- self -proxy-mappings) proxy-mappings) |
| 6859 | + (. self (_set_proxy_mappings proxy-mappings)) |
6859 | 6860 | nil) |
6860 | 6861 | "_get_proxy_mappings" (fn _get_proxy_mappings [self] |
6861 | 6862 | (.- self -proxy-mappings)) |
6862 | 6863 | "_set_proxy_mappings" (fn _set_proxy_mappings [self proxy-mappings] |
| 6864 | + (let [provided-methods (set (keys proxy-mappings))] |
| 6865 | + (when-not (.issubset provided-methods method-names) |
| 6866 | + (throw |
| 6867 | + (ex-info "Proxy override methods must correspond to methods on the declared supertypes" |
| 6868 | + {:expected method-names |
| 6869 | + :given provided-methods |
| 6870 | + :diff (.difference provided-methods method-names)})))) |
6863 | 6871 | (set! (.- self -proxy-mappings) proxy-mappings) |
6864 | 6872 | nil) |
6865 | 6873 | "_update_proxy_mappings" (fn _update_proxy_mappings [self proxy-mappings] |
|
6876 | 6884 |
|
6877 | 6885 | ;; Remove Python ``object`` from the bases if it is present to avoid errors |
6878 | 6886 | ;; about creating a consistent MRO for the given bases |
6879 | | - proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6880 | | - #_(doseq [[method-name method] methods] |
6881 | | - (println method-name method)) |
| 6887 | + proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6882 | 6888 | (python/type (basilisp.lang.util/genname "Proxy") |
6883 | 6889 | (python/tuple proxy-bases) |
6884 | 6890 | (python/dict (merge methods base-methods))))) |
|
6962 | 6968 | (. proxy (_update-proxy-mappings mappings)) |
6963 | 6969 | proxy))) |
6964 | 6970 |
|
6965 | | -;; TODO: check interface/superclass method membership |
6966 | 6971 | (defmacro proxy |
6967 | 6972 | "Create a new proxy class instance. |
6968 | 6973 |
|
|
7033 | 7038 | (assoc m method-name method))) |
7034 | 7039 | {} |
7035 | 7040 | methods)] |
7036 | | - #_(println methods) |
7037 | 7041 | `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7038 | 7042 |
|
7039 | 7043 | (defmacro proxy-super |
|
0 commit comments