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

Fixes to comparing of Python environments #23417

Merged
merged 1 commit into from
May 13, 2024
Merged
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
12 changes: 9 additions & 3 deletions src/client/pythonEnvironments/base/info/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,20 @@ export function areSameEnv(
if (leftInfo === undefined || rightInfo === undefined) {
return undefined;
}
const leftFilename = leftInfo.executable!.filename;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of the bang ! here is wrong, compiler says it can be undefined, but we're ignoring that.
And we run into issues as a result.

const rightFilename = rightInfo.executable!.filename;

if (
(leftInfo.executable?.filename && !rightInfo.executable?.filename) ||
(!leftInfo.executable?.filename && rightInfo.executable?.filename)
) {
return false;
}
if (leftInfo.id && leftInfo.id === rightInfo.id) {
// In case IDs are available, use it.
return true;
}

const leftFilename = leftInfo.executable!.filename;
const rightFilename = rightInfo.executable!.filename;

if (getEnvID(leftFilename, leftInfo.location) === getEnvID(rightFilename, rightInfo.location)) {
// Otherwise use ID function to get the ID. Note ID returned by function may itself change if executable of
// an environment changes, for eg. when conda installs python into the env. So only use it as a fallback if
Expand Down
Loading