[ty] Stop scanning a package after its first legacy namespace declaration (#29885)
## Summary
Stop scanning a package initializer once ty recognizes a legacy
namespace declaration. The resolver examines only module-level
statements and accepts the existing `pkgutil.extend_path` and
`pkg_resources.declare_namespace` forms.
On the large parser fixture, the declaration check used the following
instruction counts. These cover the top-level scan and pattern matching,
excluding the calls to obtain and load the parsed module.
| Declaration in `__init__.py` | Top-level statements | Visitor (before)
| Iterator (after) | Reduction |
| --- | ---: | ---: | ---: | ---: |
| First statement | 113 | 2,595 | 454 | 2,141 (82.5%) |
| Absent | 112 | 3,189 | 1,290 | 1,899 (59.5%) |
All three paired runs produced the same counts. The full `ty check` used
0.004% fewer instructions with the declaration first.
## Test Plan
The legacy namespace and partial stub package import mdtests passed.