Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove support for relative imports that are not prefixed with a . #85

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mypy_primer_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install git+https://github.com/hauntsaninja/mypy_primer.git
pip install git+https://github.com/detachhead/mypy_primer.git
- name: Run mypy_primer
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy_primer_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install git+https://github.com/hauntsaninja/mypy_primer.git
pip install git+https://github.com/detachhead/mypy_primer.git
- name: Run mypy_primer
shell: bash
run: |
Expand Down
5 changes: 4 additions & 1 deletion packages/pyright-internal/src/analyzer/importResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,10 @@ export class ImportResolver {

this.cachedParentImportResults.checked(current!, importName, importPath);

if (result.isImportFound) {
// TODO: figure out how namespace packages work. we disable this stupid fake relative import functionality because it's wrong
// (https://github.com/DetachHead/basedpyright/issues/76) but it seems like stub imports and some mysterious namespace package
// functionality rely on this behavior. so for now i'm just disabling it for everything except namespace packages & stub files
if (result.isImportFound && (result.isNamespacePackage || result.isStubFile)) {
// This will make cache to point to actual path that contains the module we found
importPath.importPath = current;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//// #empty

// @ts-ignore
await helper.verifyCompletion('included', 'markdown', {
await helper.verifyCompletion('excluded', 'markdown', {
marker: {
completions: [{ label: 'data_processing', kind: Consts.CompletionItemKind.Module }],
DetachHead marked this conversation as resolved.
Show resolved Hide resolved
},
Expand Down
18 changes: 3 additions & 15 deletions packages/pyright-internal/src/tests/importResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,7 @@ describe('Import tests that can run with or without a true venv', () => {
];

const importResult = getImportResult(files, ['file1']);
assert(importResult.isImportFound);
assert.strictEqual(
1,
importResult.resolvedUris.filter((f) => f.getFilePath() === combinePaths('/test', 'file1.py')).length
);
assert(!importResult.isImportFound);
});

test('import side by side file sub under src folder', () => {
Expand All @@ -545,11 +541,7 @@ describe('Import tests that can run with or without a true venv', () => {
];

const importResult = getImportResult(files, ['file1']);
assert(importResult.isImportFound);
assert.strictEqual(
1,
importResult.resolvedUris.filter((f) => f.getFilePath() === combinePaths('/src/nested', 'file1.py')).length
);
assert(!importResult.isImportFound);
});

test('import file sub under containing folder', () => {
Expand All @@ -565,11 +557,7 @@ describe('Import tests that can run with or without a true venv', () => {
];

const importResult = getImportResult(files, ['file1']);
assert(importResult.isImportFound);
assert.strictEqual(
1,
importResult.resolvedUris.filter((f) => f.getFilePath() === combinePaths('/src/nested', 'file1.py')).length
);
assert(!importResult.isImportFound);
});

test("don't walk up the root", () => {
Expand Down
Loading