From 95fef43c4d73aa01fa5f8eaa0dcc1fffffecbb14 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 6 Feb 2023 21:13:23 -0500 Subject: [PATCH] Add some additional tests for relative imports --- .../resources/test/fixtures/pyflakes/project/foo/bar.py | 7 +++++++ .../test/fixtures/pyflakes/project/foo/bop/baz.py | 7 +++++++ ...s__pyflakes__tests__nested_relative_typing_module.snap | 8 ++++---- ...f__rules__pyflakes__tests__relative_typing_module.snap | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bar.py b/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bar.py index 72092bf000..9777851b0b 100644 --- a/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bar.py +++ b/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bar.py @@ -12,6 +12,13 @@ def f(): x: Literal["foo"] +def f(): + from . import typical + + # OK + x: typical.Literal["foo"] + + def f(): from .atypical import Literal diff --git a/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bop/baz.py b/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bop/baz.py index cc312a5ee8..83891a3ba9 100644 --- a/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bop/baz.py +++ b/crates/ruff/resources/test/fixtures/pyflakes/project/foo/bop/baz.py @@ -12,6 +12,13 @@ def f(): x: Literal["foo"] +def f(): + from .. import typical + + # OK + x: typical.Literal["foo"] + + def f(): from .typical import Literal diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap index 6ae7adf513..558cf66a17 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap @@ -6,10 +6,10 @@ expression: diagnostics UndefinedName: name: foo location: - row: 19 + row: 26 column: 15 end_location: - row: 19 + row: 26 column: 20 fix: ~ parent: ~ @@ -17,10 +17,10 @@ expression: diagnostics UndefinedName: name: foo location: - row: 26 + row: 33 column: 15 end_location: - row: 26 + row: 33 column: 20 fix: ~ parent: ~ diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap index 73dcdcb27b..fe0d50ef18 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap @@ -6,10 +6,10 @@ expression: diagnostics UndefinedName: name: foo location: - row: 19 + row: 26 column: 15 end_location: - row: 19 + row: 26 column: 20 fix: ~ parent: ~