Skip to content

Commit ae360e5

Browse files
authored
Do not warn on unused bindings whose names begin with _ (#757)
Hi, could you please review patch to not work on unused bindings whose name begins with `_`. It addresses #756. I've addressed some of such warnings coming up when running the nrepl-server, and added a test. Thanks --------- Co-authored-by: ikappaki <[email protected]>
1 parent e2f4434 commit ae360e5

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
* Fix an issue where the constructors of types created by `deftype` and `defrecord` could not be called if they contained `-` characters (#777)
2424
* Fix issue with the variadic ampersand operator treated as a binding in macros (#772)
2525

26+
### Changed
27+
* Do not warn on unused bindings when their name begins with `_` (#756).
28+
2629
## [v0.1.0b0]
2730
### Added
2831
* Added rudimentary support for `clojure.stacktrace` with `print-cause-trace` (part of #721)

src/basilisp/contrib/bencode.lpy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
(extend-protocol BEncodeable
1717
nil
18-
(to-bencode-encodeable* [this]
18+
(to-bencode-encodeable* [_]
1919
#b "0:")
2020
python/bytes
2121
(to-bencode-encodeable* [this]
@@ -193,7 +193,7 @@
193193
be specified if ``:keywordize-keys`` is also specified
194194
:keyword ``:string-fn``: a function which will be called for each byte string which
195195
is not a map key; default is :lpy:fn:`basilisp.core/identity`"
196-
[data {:keys [keywordize-keys key-fn string-fn] :as opts}]
196+
[data {:keys [keywordize-keys key-fn] :as opts}]
197197
(when (and keywordize-keys key-fn)
198198
(throw (ex-info "Can only specify either :keywordize-keys or :key-fn; not both"
199199
{:keywordize-keys keywordize-keys
@@ -203,7 +203,7 @@
203203
(assoc :key-fn #(keyword (.decode % "utf-8")))))]
204204
(try
205205
(decode* data opts)
206-
(catch python/Exception e
206+
(catch python/Exception _
207207
[nil data]))))
208208

209209
(defn decode-all

src/basilisp/contrib/nrepl_server.lpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
(defn- send-value [request send-fn v]
8585
(let [{:keys [client*]} request
86-
{:keys [*2 *3 *e]} @client*
86+
{:keys [*1 *2]} @client*
8787
[v opts] v
8888
ns (:ns opts)]
8989
(swap! client* assoc :*1 v :*2 *1 :*3 *2)
@@ -337,7 +337,7 @@
337337
(warn "Unhandled operation" op)
338338
(send-fn request {"status" ["error" "unknown-op" "done"]}))))
339339

340-
(defn- make-request-handler [opts]
340+
(defn- make-request-handler [_]
341341
(-> handle-request
342342
coerce-request-mw
343343
log-request-mw))

src/basilisp/lang/compiler/analyzer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ def _warn_unused_names(self):
254254
), "Only warn when logger is configured for WARNING level"
255255
ns = runtime.get_current_ns()
256256
for _, entry in self._table.items():
257+
if entry.symbol.name.startswith("_"):
258+
continue
257259
if entry.symbol in _NO_WARN_UNUSED_SYMS:
258260
continue
259261
if entry.warn_if_unused and not entry.used:

tests/basilisp/compiler_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,12 @@ def test_single_arity_fn_log_if_warning_enabled(
22452245
f"symbol 'v' defined but not used ({ns}: 1)",
22462246
) in caplog.record_tuples
22472247

2248+
def test_single_arity_fn_underscore_log_if_warning_enabled(
2249+
self, lcompile: CompileFn, ns: runtime.Namespace, caplog
2250+
):
2251+
lcompile("(fn [_v] (fn [v] v))", opts={compiler.WARN_ON_UNUSED_NAMES: True})
2252+
assert_no_logs(caplog)
2253+
22482254
def test_multi_arity_fn_log_if_warning_enabled(
22492255
self, lcompile: CompileFn, ns: runtime.Namespace, caplog
22502256
):

0 commit comments

Comments
 (0)