ruff/crates/ty_python_semantic/resources/mdtest/import
Eric Jolibois 0095ff4c1a
[ty] Implement module-level __getattr__ support (#19791)
fix https://github.com/astral-sh/ty/issues/943

## Summary

Add module-level `__getattr__` support for ty's type checker, fixing
issue https://github.com/astral-sh/ty/issues/943.
Module-level `__getattr__` functions ([PEP
562](https://peps.python.org/pep-0562/)) are now respected when
resolving dynamic attributes, matching the behavior of mypy and pyright.

## Implementation

Thanks @sharkdp for the guidance in
https://github.com/astral-sh/ty/issues/943#issuecomment-3157566579
- Adds module-specific `__getattr__` resolution in
`ModuleLiteral.static_member()`
- Maintains proper attribute precedence: explicit attributes >
submodules > `__getattr__`

## Test Plan
- New mdtest covering basic functionality, type annotations, attribute
precedence, and edge cases
(run ```cargo nextest run -p ty_python_semantic
mdtest__import_module_getattr```)
- All new tests pass, verifying `__getattr__` is called correctly and
returns proper types
  - Existing test suite passes, ensuring no regressions introduced
2025-08-08 10:39:37 -07:00
..
basic.md [ty] don't allow first-party code to shadow stdlib types module (#19128) 2025-07-04 10:36:26 +00:00
builtins.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
case_sensitive.md
conditional.md
conflicts.md
conventions.md [ty] Add support for __all__ (#17856) 2025-05-07 21:42:42 +05:30
cyclic.md [ty] Recognize submodules in self-referential imports (#18005) 2025-05-13 16:59:11 +02:00
dunder_all.md [ty] Understand classes that inherit from subscripted Protocol[] as generic (#17832) 2025-05-09 17:39:15 +01:00
errors.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
invalid_syntax.md
module_getattr.md [ty] Implement module-level __getattr__ support (#19791) 2025-08-08 10:39:37 -07:00
namespace.md [ty] Support import <namespace> and from <namespace> import module (#18137) 2025-05-21 07:28:33 +00:00
relative.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
site_packages_discovery.md [ty] Improve tests for site-packages discovery (#18374) 2025-05-30 07:32:21 +01:00
star.md [ty] Support as-patterns in reachability analysis (#19728) 2025-08-04 20:13:50 +02:00
stub_packages.md [ty] Fix relative imports in stub packages (#18132) 2025-05-16 15:30:10 +02:00
stubs.md
tracking.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00