Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix an issue with `basilisp test` standard streams output that can lead to failures on MS-Windows (#1080)
* Fix an issue where destructuring a vector would throw an exception rather than returning `nil` for invalid key types (#1090)
* Fix an issue where destructuring default values would take precedence over falsey values in the source data structure (#1078)
* Fixed a bug where imported Python names containing `-` (in lieu of `_`) could not be referenced using the `-` syntax (#1085)

### Removed
* Removed support for Python 3.8 (#1083)
Expand Down
9 changes: 7 additions & 2 deletions src/basilisp/lang/compiler/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3505,8 +3505,13 @@ def __resolve_namespaced_symbol_in_ns(
namespace portion"""
assert form.ns is not None

# Import names are always munged by the compiler when they're added to imports,
# but if the user provides an import alias that is left untouched. Check for
# the munged symbol in `Namespace.imports` and the unmunged in
# `Namespace.import_aliases`.
ns_sym = sym.symbol(form.ns)
if ns_sym in which_ns.imports or ns_sym in which_ns.import_aliases:
import_sym = sym.symbol(munge(form.ns))
if import_sym in which_ns.imports or ns_sym in which_ns.import_aliases:
# Fetch the full namespace name for the aliased namespace/module.
# We don't need this for actually generating the link later, but
# we _do_ need it for fetching a reference to the module to check
Expand All @@ -3516,7 +3521,7 @@ def __resolve_namespaced_symbol_in_ns(
assert ns is not None
ns_name = ns.name
else:
ns_name = ns_sym.name
ns_name = import_sym.name

safe_module_name = munge(ns_name)
assert (
Expand Down
14 changes: 14 additions & 0 deletions tests/basilisp/compiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import inspect
import logging
import os
import pathlib
import re
import sys
import textwrap
Expand Down Expand Up @@ -6387,6 +6388,19 @@ def test_aliased_namespace_not_hidden_by_python_module(
monkeypatch.chdir(cwd)
os.unlink(module_file_path)

def test_import_name_with_underscores_resolves_properly(
self,
lcompile: CompileFn,
monkeypatch: pytest.MonkeyPatch,
tmp_path: pathlib.Path,
):
package = tmp_path / "a_b"
package.mkdir(parents=True)
file = package / "c.py"
file.write_text("val = 10")
monkeypatch.syspath_prepend(str(tmp_path))
assert lcompile("(import a-b.c) [a-b.c/val a_b.c/val]") == vec.v(10, 10)

@pytest.mark.parametrize(
"code",
[
Expand Down