-
Notifications
You must be signed in to change notification settings - Fork 227
Closed as not planned
Labels
questionAsking for support or clarificationAsking for support or clarification
Description
Summary
Attempting to access a module-level object (attribute) that is set dynamically (e.g. with setattr or globals()) results in an unresolved-attribute warning, despite the attribute being actually resolvable.
Consider this toy example:
example.py
globals()["EXAMPLE"] = Truetest_example.py
import example
if example.EXAMPLE:
print("Example is True")Python output
$ python test_example.py
Example is Truety output
$ uvx ty check example.py test_example.py
error[unresolved-attribute]: Module `example` has no member `EXAMPLE`
--> test_example.py:3:4
|
1 | import example
2 |
3 | if example.EXAMPLE:
| ^^^^^^^^^^^^^^^
4 | print("Example is True")
|
info: rule `unresolved-attribute` is enabled by default
Found 1 diagnosticA more realistic example (how I actually got here) is when using the astropy.constants module:
test_astropy.py
from astropy import constants
print(f"Speed of light: {constants.c.value} m/s")Python output
$ uv run test_astropy.py
Speed of light: 299792458.0 m/sty output
$ uvx ty check test_astropy.py
error[unresolved-attribute]: Module `astropy.constants` has no member `c`
--> test_astropy.py:2:26
|
1 | from astropy import constants
2 | print(f"Speed of light: {constants.c.value} m/s")
| ^^^^^^^^^^^
|
info: rule `unresolved-attribute` is enabled by default
Found 1 diagnosticApologies if this is a duplicate of an existing report, I looked but didn't see anything obvious.
Version
ty 0.0.3
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionAsking for support or clarificationAsking for support or clarification