Clarify :fresh usage in import#1607
Conversation
|
That does seem clearer. I guess if it had errored when using |
|
Yup! Especially if there was "did you mean ..." in the error message. I'll try to write a guard like that. |
|
@sogaiu Done. I tried fitting the style of asserts already in place. These error out properly: (import ./mymod :fresh)
(import ./mymod :as mine :fresh)This one also works like it should (doesn't error out): (import ./mymod :fresh nil)This one still passes the wrong args further down, but I don't think there's much we can do about that: (import ./mymod :fresh :as mine) |
|
May be there's some way to add tests for the cases you posted? FWIW, I see some testing of My impression is that So for the last case: (import ./mymod :fresh :as mine)if we check that It might not check for |
|
Thank you @sogaiu, based on your comment I managed to make it better :) Please check if the current code is okay. |
|
Thanks for your continued efforts :) Nice to see some tests -- I think it could be worth also adding the last two examples you mentioned in this comment. WDYT? Sorry I was mistaken in my description in this comment earlier about:
I think it's not the length of In any case, for: (def ps (partition 2 args))
(each p ps
(def k (first p))
(assert (= (length p) 2) (string/format "%j needs a value" k))
(assert (keyword? (first p)) (string/format "expected keyword, got %s: %j" (type k) k)))
(def argm (mapcat (fn [[k v]] [k (case k :as (string v) :only ~(quote ,v) v)]) ps))how about something like the following? (assertf (even? (length args)) "args should have even length: %n" args)
(def ps (partition 2 args))
(def argm
(mapcat (fn [[k v]]
(assertf (keyword? k) "expected keyword, got %s: %n" (type k) k)
[k (case k :as (string v) :only ~(quote ,v) v)])
ps))This way we only traverse [1] The docstring for
I think it's cheap to determine the length (it's a lookup IIUC). Although for |
|
I added your suggestions and cleaned up a bit. Let me know what you think |
|
LGTM. I hope others are ok with it too :) |
This confused me a lot, because I kept calling
(import ./mymodule :fresh)and it wouldn't reload anything.