Repository: astral-sh/ruff
File: crates/ruff_linter/src/checkers/ast/mod.rs (Rust)

Code before:
        } else {
            "typing_extensions"
        };
        Some(TypingImporter {
            checker: self,
            source_module,
            member,
        })
    }
}

pub(crate) struct TypingImporter<'a, 'b> {
    checker: &'a Checker<'b>,
    source_module: &'static str,
    member: &'a str,
}

impl TypingImporter<'_, '_> {
    /// Create an [`Edit`] that makes the requested symbol available at `position`.
    ///
    /// See [`Importer::get_or_import_symbol`] for more details on the returned values and
    /// [`Checker::typing_importer`] for a way to construct a [`TypingImporter`].
    pub(crate) fn import(&self, position: TextSize) -> Result<(Edit, String), ResolutionError> {
        let request = ImportRequest::import_from(self.source_module, self.member);
        self.checker
            .importer
            .get_or_import_symbol(&request, position, self.checker.semantic())
    }
}

impl SemanticSyntaxContext for Checker<'_> {
    fn python_version(&self) -> PythonVersion {
        self.target_version.unwrap_or_else(PythonVersion::latest)
    }

    fn global(&self, name: &str) -> Option<TextRange> {
        self.semantic.global(name)
    }

    fn report_semantic_error(&self, error: SemanticSyntaxError) {
        match error.kind {
            SemanticSyntaxErrorKind::LateFutureImport => {
                if self.settings.rules.enabled(Rule::LateFutureImport) {
                    self.report_diagnostic(Diagnostic::new(LateFutureImport, error.range));
                }
            }
            SemanticSyntaxErrorKind::LoadBeforeGlobalDeclaration { name, start } => {
                if self
                    .settings
                    .rules
                    .enabled(Rule::LoadBeforeGlobalDeclaration)

Review comment (suggestion):
It would be great to have a comment here explaining why we use `latest` instead of default. It's very subtle

Code after:
        } else {
            "typing_extensions"
        };
        Some(TypingImporter {
            checker: self,
            source_module,
            member,
        })
    }
}

pub(crate) struct TypingImporter<'a, 'b> {
    checker: &'a Checker<'b>,
    source_module: &'static str,
    member: &'a str,
}

impl TypingImporter<'_, '_> {
    /// Create an [`Edit`] that makes the requested symbol available at `position`.
    ///
    /// See [`Importer::get_or_import_symbol`] for more details on the returned values and
    /// [`Checker::typing_importer`] for a way to construct a [`TypingImporter`].
    pub(crate) fn import(&self, position: TextSize) -> Result<(Edit, String), ResolutionError> {
        let request = ImportRequest::import_from(self.source_module, self.member);
        self.checker
            .importer
            .get_or_import_symbol(&request, position, self.checker.semantic())
    }
}

impl SemanticSyntaxContext for Checker<'_> {
    fn python_version(&self) -> PythonVersion {
        // Reuse `parser_version` here, which should default to `PythonVersion::latest` instead of
        // `PythonVersion::default` to minimize version-related semantic syntax errors when
        // `target_version` is unset.
        self.target_version.parser_version()
    }

    fn global(&self, name: &str) -> Option<TextRange> {
        self.semantic.global(name)
    }

    fn report_semantic_error(&self, error: SemanticSyntaxError) {
        match error.kind {
            SemanticSyntaxErrorKind::LateFutureImport => {
                if self.settings.rules.enabled(Rule::LateFutureImport) {
                    self.report_diagnostic(Diagnostic::new(LateFutureImport, error.range));
                }
            }
            SemanticSyntaxErrorKind::LoadBeforeGlobalDeclaration { name, start } => {
                if self