|
6887 | 6887 | "Generate a proxy class with the given bases."
|
6888 | 6888 | [bases]
|
6889 | 6889 | (let [methods (apply hash-map (mapcat proxy-base-methods bases))
|
| 6890 | + method-names (set (map munge (keys methods))) |
6890 | 6891 | base-methods {"__init__" (fn __init__ [self proxy-mappings & args]
|
6891 | 6892 | (apply (.- (python/super (.- self __class__) self) __init__) args)
|
6892 |
| - (set! (.- self -proxy-mappings) proxy-mappings) |
| 6893 | + (. self (_set_proxy_mappings proxy-mappings)) |
6893 | 6894 | nil)
|
6894 | 6895 | "_get_proxy_mappings" (fn _get_proxy_mappings [self]
|
6895 | 6896 | (.- self -proxy-mappings))
|
6896 | 6897 | "_set_proxy_mappings" (fn _set_proxy_mappings [self proxy-mappings]
|
| 6898 | + (let [provided-methods (set (keys proxy-mappings))] |
| 6899 | + (when-not (.issubset provided-methods method-names) |
| 6900 | + (throw |
| 6901 | + (ex-info "Proxy override methods must correspond to methods on the declared supertypes" |
| 6902 | + {:expected method-names |
| 6903 | + :given provided-methods |
| 6904 | + :diff (.difference provided-methods method-names)})))) |
6897 | 6905 | (set! (.- self -proxy-mappings) proxy-mappings)
|
6898 | 6906 | nil)
|
6899 | 6907 | "_update_proxy_mappings" (fn _update_proxy_mappings [self proxy-mappings]
|
|
6910 | 6918 |
|
6911 | 6919 | ;; Remove Python ``object`` from the bases if it is present to avoid errors
|
6912 | 6920 | ;; about creating a consistent MRO for the given bases
|
6913 |
| - proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6914 |
| - #_(doseq [[method-name method] methods] |
6915 |
| - (println method-name method)) |
| 6921 | + proxy-bases (concat (remove #{python/object} bases) [basilisp.lang.interfaces/IProxy])] |
6916 | 6922 | (python/type (basilisp.lang.util/genname "Proxy")
|
6917 | 6923 | (python/tuple proxy-bases)
|
6918 | 6924 | (python/dict (merge methods base-methods)))))
|
|
6996 | 7002 | (. proxy (_update-proxy-mappings mappings))
|
6997 | 7003 | proxy)))
|
6998 | 7004 |
|
6999 |
| -;; TODO: check interface/superclass method membership |
7000 | 7005 | (defmacro proxy
|
7001 | 7006 | "Create a new proxy class instance.
|
7002 | 7007 |
|
|
7067 | 7072 | (assoc m method-name method)))
|
7068 | 7073 | {}
|
7069 | 7074 | methods)]
|
7070 |
| - #_(println methods) |
7071 | 7075 | `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args)))
|
7072 | 7076 |
|
7073 | 7077 | (defmacro proxy-super
|
|
0 commit comments