Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Bug and test fixes - #1322

Merged
Alexander Sher (AlexanderSher) merged 4 commits into
microsoft:masterfrom
AlexanderSher:Fix1314
Jul 12, 2019
Merged

Alexander Sher (AlexanderSher) merged 4 commits into
microsoft:masterfrom
AlexanderSher:Fix1314

Conversation

@AlexanderSher

@AlexanderSher Alexander Sher (AlexanderSher) commented Jul 12, 2019 •

Copy link
Copy Markdown
Contributor

- Fixes microsoft#1151: Reliable way to determine final analysis of a module
- Fixes microsoft#1201: NRE in SymbolCollector.AddProperty
- Fixes microsoft#1228: NRE in TryFindMissingDependencies
- Fixes microsoft#1294: Handle valid case for reloading AST
- Fixes microsoft#1295: FindReferences doesn't work on package init members
- Fixes microsoft#1296: DependencyResolver graph misses intermediate imports
- Part of the fix for microsoft#1174: All references are not listed when using ms language server
- Fix microsoft#1318: PathUtils.IsNormalizedPath and PathUtils.NormalizePath work incorrectly with UNC
- Fix microsoft#1320: Incorrect relative import handling in Python 2x
- Fix microsoft#1321: If one user paths is part of the name of another, PathResolverSnapshot is built incorrectly
- Fix paths in tests
- Remove IModuleManagement.SetUserSearchPaths

public static bool PathStartsWith(string s, string prefix)
=> s != null && s.StartsWith(prefix, StringExtensions.PathsStringComparison) &&
(s.Length == prefix.Length || IsDirectorySeparator(s[prefix.Length]));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is fix for #1321, to ensure that part of folder name isn't considered as part of the path.

private void LogCompleted(IDependencyChainNode<PythonAnalyzerEntry> node, IPythonModule module, Stopwatch stopWatch, TimeSpan startTime) {
if (_log != null) {
var completed = node != null && module.Analysis is LibraryAnalysis ? "completed" : "completed for library";
var completed = node != null && module.Analysis is LibraryAnalysis ? "completed for library" : "completed ";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct logging

} else if (firstModule != default && !string.IsNullOrEmpty(importNames[0])) {
var firstName = moduleImportExpression.Names[0];
Eval.DeclareVariable(importNames[0], variableModule, VariableSource.Import, firstName);
Eval.DeclareVariable(importNames[0], firstModule, VariableSource.Import, firstName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is part of the fix for #1320. Name of the module may not match the name of the variable in Python 2x


// If __all__ is present, take it, otherwise declare all members from the module that do not begin with an underscore.
var memberNames = variableModule.Analysis.StarImportMemberNames ?? variableModule.GetMemberNames().Where(s => !s.StartsWithOrdinal("_"));
var memberNames = variableModule.Analysis?.StarImportMemberNames ?? variableModule.GetMemberNames().Where(s => !s.StartsWithOrdinal("_"));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If variableModule represents implicit package, Analysis will be null.

Choose a reason for hiding this comment

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

Kinda dangerous... Maybe have it attach empty analysis?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Empty analysis requires IDocument but there is actually no document - it is an implicit package.

Choose a reason for hiding this comment

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

OK


// If __all__ is present, take it, otherwise declare all members from the module that do not begin with an underscore.
var memberNames = variableModule.Analysis.StarImportMemberNames ?? variableModule.GetMemberNames().Where(s => !s.StartsWithOrdinal("_"));
var memberNames = variableModule.Analysis?.StarImportMemberNames ?? variableModule.GetMemberNames().Where(s => !s.StartsWithOrdinal("_"));

Choose a reason for hiding this comment

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

Should module have at least empty analysis always? I think there is a lot of code that assumes that.

return "\"{0}\"".FormatInvariant(arg);
}

public static bool PathStartsWith(this string s, string prefix)

Choose a reason for hiding this comment

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

Should we have it instead calling PathUtils.PathStartsWith ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We have a bit of a mess in our extensions. From my understanding, StringExtensions should have things that are applicable to any strings, PathUtils should have string operations that are related to paths only, and FileSystemExtensions should have things like FindFile.

@AlexanderSher
Alexander Sher (AlexanderSher) merged commit 4e2d30f into microsoft:master Jul 12, 2019
Jake Bailey (jakebailey) pushed a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
- Fix microsoft#1314: NRE in HandleModuleImportStar bug
- Fix microsoft#1318: PathUtils.IsNormalizedPath and PathUtils.NormalizePath work incorrectly with UNC
- Fix microsoft#1320: Incorrect relative import handling in Python 2x
- Fix microsoft#1321: If one user paths is part of the name of another, PathResolverSnapshot is built incorrectly
- Fix paths in tests
- Remove IModuleManagement.SetUserSearchPaths
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

3 participants