Repository: astral-sh/ruff
File: crates/ty_ide/src/symbols.rs (Rust)

Code before:
    /// Tests that a work-around which unions `__all__` values lets
    /// us find conditionally exported symbols.
    ///
    /// However, this also means that we may suggest exported symbols
    /// even when they aren't available. What we should ideally do is
    /// evaluate the conditional like ty does, but this requires some
    /// work. (And it's unlikely auto-import will ever get the full
    /// evaluation capabilities as ty, so it's likely this sort of
    /// union work-around will always be something we do in at least
    /// some cases.)
    #[test]
    fn union_all_to_work_around_conditional_symbols() {
        let test = PublicTestBuilder::default()
            .source(
                "test.py",
                "
                import sys
                if sys.version_info >= (3, 11):
                    ZQZQZQ = 1
                else:
                    ZYZYZY = 1

                if sys.version_info >= (3, 11):
                    __all__ = ['ZQZQZQ']
                else:
                    __all__ = ['ZYZYZY]
                ",
            )
            .build();
        insta::assert_snapshot!(
            test.exports(),
            @"ZQZQZQ :: Constant",
        );
    }

    #[test]
    fn deprecated_function() {
        let test = public_test(
            "\
@deprecated('use new_foo instead')
def foo(): ...

def bar(): ...
",
        );
        let symbols = test.exported_symbols();

        let syms: Vec<_> = symbols.iter().collect();
        assert_eq!(syms.len(), 2);

        let (_, foo) = &syms[0];

Review comment (suggestion):
this string appears unclosed. Is that why `ZQZQZQ` is currently listed as an export in this test, but `ZYZYZY` is not? I'd expect them both to be listed; that seems to be the behaviour described by your PR summary and the behaviour I see in playground builds locally on this branch


```suggestion
                    __all__ = ['ZYZYZY']
```

Code after:

    /// Tests that a work-around which unions `__all__` values lets
    /// us find conditionally exported symbols.
    ///
    /// However, this also means that we may suggest exported symbols
    /// even when they aren't available. What we should ideally do is
    /// evaluate the conditional like ty does, but this requires some
    /// work. (And it's unlikely auto-import will ever get the full
    /// evaluation capabilities as ty, so it's likely this sort of
    /// union work-around will always be something we do in at least
    /// some cases.)
    #[test]
    fn union_all_to_work_around_conditional_symbols_py311() {
        let test = PublicTestBuilder::default()
            .python_version(PythonVersion::PY311)
            .source(
                "test.py",
                "
                import sys
                if sys.version_info >= (3, 11):
                    ZQZQZQ = 1
                else:
                    ZYZYZY = 1

                if sys.version_info >= (3, 11):
                    __all__ = ['ZQZQZQ']
                else:
                    __all__ = ['ZYZYZY']
                ",
            )
            .build();
        // Ideally this would only have `ZQZQZQ`.
        insta::assert_snapshot!(
            test.exports(),
            @r"
        ZQZQZQ :: Constant
        ZYZYZY :: Constant
        ",
        );
    }

    /// Like `union_all_to_work_around_conditional_symbols_py311`, but
    /// sets the environment Python version to 3.10 so that the conditional
    /// should evaluate to false.
    #[test]
    fn union_all_to_work_around_conditional_symbols_py310() {
        let test = PublicTestBuilder::default()
            .python_version(PythonVersion::PY310)
            .source(
                "test.py",
                "