clojure.core/keyword takes a string and returns a keyword. However, in order to support certain behaviours the function returns nil whenever it gets something that is not a string, symbol or keyword, instead of crashing.
This is unfortunate for type checking, since you cannot assume keyword will return not-nil even when the type checker can prove that it's being called with a string, forcing you to pollute the codebase with nilable specs.
This can be fixed with the following ann:
(spectrum.ann/ann #'keyword
(fn [fnspec argspec]
(if (#{#'clojure.core/symbol?
#'clojure.core/keyword?
#'clojure.core/string?}
(-> argspec :ps first :pred))
(-> fnspec
(update-in [:ret :ps] pop)
(update-in [:ret :ks] pop))
fnspec)))
Would this be a good addition to ann.clj?
clojure.core/keywordtakes a string and returns a keyword. However, in order to support certain behaviours the function returns nil whenever it gets something that is not a string, symbol or keyword, instead of crashing.This is unfortunate for type checking, since you cannot assume keyword will return not-nil even when the type checker can prove that it's being called with a string, forcing you to pollute the codebase with nilable specs.
This can be fixed with the following ann:
Would this be a good addition to ann.clj?