summaryrefslogtreecommitdiff
path: root/setuptools/tests/config/test_expand.py
diff options
context:
space:
mode:
authorKarl Otness <karl@karlotness.com>2022-06-15 21:05:57 -0400
committerKarl Otness <karl@karlotness.com>2022-06-18 22:24:36 -0400
commit685c80c864f05ee37db31246ff125639aa38432e (patch)
treed6a9b38ad859a37785e9d71b38b0b7c0285ba789 /setuptools/tests/config/test_expand.py
parentbe632321303dd15ef19c97cec8cd9c8239522655 (diff)
downloadpython-setuptools-git-685c80c864f05ee37db31246ff125639aa38432e.tar.gz
Add support for annotated assignments to static attribute lookup.
When walking the ast of a module, look for AnnAssign nodes in addition to Assign to support assignments with type annotations, for example. Since we have to read different attributes, split the generators into a for loop. Existing ast.Assign nodes follow the same processing as before.
Diffstat (limited to 'setuptools/tests/config/test_expand.py')
-rw-r--r--setuptools/tests/config/test_expand.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/setuptools/tests/config/test_expand.py b/setuptools/tests/config/test_expand.py
index 15053c8f..a1f54386 100644
--- a/setuptools/tests/config/test_expand.py
+++ b/setuptools/tests/config/test_expand.py
@@ -85,6 +85,18 @@ class TestReadAttr:
values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'}, tmp_path)
assert values['c'] == (0, 1, 1)
+ def test_read_annotated_attr(self, tmp_path):
+ files = {
+ "pkg/__init__.py": "",
+ "pkg/sub/__init__.py": (
+ "VERSION: str = '0.1.1'\n"
+ "raise SystemExit(1)\n"
+ ),
+ }
+ write_files(files, tmp_path)
+ # Make sure this attribute can be read statically
+ assert expand.read_attr('pkg.sub.VERSION', root_dir=tmp_path) == '0.1.1'
+
def test_import_order(self, tmp_path):
"""
Sometimes the import machinery will import the parent package of a nested