Skip to content

Commit

Permalink
Do not warn on unused bindings whose names begin with _
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Dec 29, 2023
1 parent a25771a commit fd0674b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
* Basilisp now supports PyTest 7.0+ (#660)
* Do not warn on unused bindings when their name begins with `_` (#756).

### Fixed
* Fix issue with `case` evaluating all of its clauses expressions (#699)
Expand Down
6 changes: 3 additions & 3 deletions src/basilisp/contrib/bencode.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

(extend-protocol BEncodeable
nil
(to-bencode-encodeable* [this]
(to-bencode-encodeable* [_this]
#b "0:")
python/bytes
(to-bencode-encodeable* [this]
Expand Down Expand Up @@ -193,7 +193,7 @@
be specified if ``:keywordize-keys`` is also specified
:keyword ``:string-fn``: a function which will be called for each byte string which
is not a map key; default is :lpy:fn:`basilisp.core/identity`"
[data {:keys [keywordize-keys key-fn string-fn] :as opts}]
[data {:keys [keywordize-keys key-fn] :as opts}]
(when (and keywordize-keys key-fn)
(throw (ex-info "Can only specify either :keywordize-keys or :key-fn; not both"
{:keywordize-keys keywordize-keys
Expand All @@ -203,7 +203,7 @@
(assoc :key-fn #(keyword (.decode % "utf-8")))))]
(try
(decode* data opts)
(catch python/Exception e
(catch python/Exception _e
[nil data]))))

(defn decode-all
Expand Down
4 changes: 2 additions & 2 deletions src/basilisp/contrib/nrepl_server.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

(defn- send-value [request send-fn v]
(let [{:keys [client*]} request
{:keys [*2 *3 *e]} @client*
{:keys [*1 *2]} @client*
[v opts] v
ns (:ns opts)]
(swap! client* assoc :*1 v :*2 *1 :*3 *2)
Expand Down Expand Up @@ -337,7 +337,7 @@
(warn "Unhandled operation" op)
(send-fn request {"status" ["error" "unknown-op" "done"]}))))

(defn- make-request-handler [opts]
(defn- make-request-handler [_opts]
(-> handle-request
coerce-request-mw
log-request-mw))
Expand Down
3 changes: 1 addition & 2 deletions src/basilisp/io.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@

(defn- clean-writer-mode
[opts]
(let [append? (:append opts)
mode (:mode opts "")
(let [mode (:mode opts "")
clean-mode (cond
(:append opts) (str "a" mode)
(not (str/includes? mode "w")) (str "w" mode)
Expand Down
2 changes: 2 additions & 0 deletions src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def _warn_unused_names(self):
), "Only warn when logger is configured for WARNING level"
ns = runtime.get_current_ns()
for _, entry in self._table.items():
if entry.symbol.name.startswith("_"):
continue
if entry.symbol in _NO_WARN_UNUSED_SYMS:
continue
if entry.warn_if_unused and not entry.used:
Expand Down
6 changes: 6 additions & 0 deletions tests/basilisp/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,12 @@ def test_single_arity_fn_log_if_warning_enabled(
f"symbol 'v' defined but not used ({ns}: 1)",
) in caplog.record_tuples

def test_single_arity_fn_underscore_log_if_warning_enabled(
self, lcompile: CompileFn, ns: runtime.Namespace, caplog
):
lcompile("(fn [_v] (fn [v] v))", opts={compiler.WARN_ON_UNUSED_NAMES: True})
assert_no_logs(caplog)

def test_multi_arity_fn_log_if_warning_enabled(
self, lcompile: CompileFn, ns: runtime.Namespace, caplog
):
Expand Down

0 comments on commit fd0674b

Please sign in to comment.