-
Notifications
You must be signed in to change notification settings - Fork 133
Allows to use .pyi file annotations supplement to .py files in analysis core #331
Changes from all commits
c9ffa58
7930d3b
5e629bb
976133f
2780183
96e5da7
3af9a96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,24 @@ public static bool SetEquals<T>(this IEnumerable<T> source, IEnumerable<T> other | |
| public static IEnumerable<T> Keys<T, U>(this IEnumerable<KeyValuePair<T, U>> source) => source.Select(GetKey); | ||
| public static IEnumerable<T> ExcludeDefault<T>(this IEnumerable<T> source) => source.Where(i => !Equals(i, default(T))); | ||
|
|
||
| /// <summary> | ||
| /// Returns the only element of sequence, or the default value of <typeparamref name="T"/>, if sequence has <> 1 elements. | ||
| /// </summary> | ||
| public static T OnlyOneOrDefault<T>(this IEnumerable<T> source) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has a different semantics. SingleOrDefault throws if there's more than 1 element. This one returns default.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning here is one would use OnlyOneOrDefault when they want to make a decision based on unambiguous analysis result, if there is no expectation of lack of ambiguity. |
||
| using (var enumerator = source.GetEnumerator()) { | ||
| if (!enumerator.MoveNext()) { | ||
| return default(T); | ||
| } | ||
|
|
||
| T result = enumerator.Current; | ||
|
|
||
| if (enumerator.MoveNext()) { | ||
| return default(T); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
|
|
||
| public static IEnumerable<T> TraverseBreadthFirst<T>(this T root, Func<T, IEnumerable<T>> selectChildren) { | ||
| var items = new Queue<T>(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ internal sealed class ProjectEntry : IPythonProjectEntry, IAggregateableProjectE | |
| private readonly HashSet<AggregateProjectEntry> _aggregates = new HashSet<AggregateProjectEntry>(); | ||
|
|
||
| private TaskCompletionSource<IModuleAnalysis> _analysisTcs = new TaskCompletionSource<IModuleAnalysis>(); | ||
| private AnalysisUnit _unit; | ||
| internal AnalysisUnit _unit; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need it to be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in ModuleInfo.AnalysisUnit.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With some exceptions, fields should be private, they should be wrapped with properties or access methods. But in this case, it is not safe to provide
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could add a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Analysis is single threaded, but it is in parallel with parsing. Unfortunately, you can't do it like with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am open for suggestions. Actually, at this moment I don't understand how can parsing be completed in parallel to analysis without race conditions. Here's the relevant code excerpt from _unit = new AnalysisUnit(tree, MyScope.Scope);
AnalysisLog.NewUnit(_unit);
MyScope.Scope.Children = new List<InterpreterScope>();
MyScope.Scope.ClearNodeScopes();
MyScope.Scope.ClearNodeValues();
MyScope.Scope.ClearLinkedVariables();
MyScope.Scope.ClearVariables();
MyScope.ClearReferencedModules();
MyScope.ClearUnresolvedModules();
_unit.State.ClearDiagnostics(this);There does not seem to be anything, that would prevent modification of MyScope.* if there might be an analysis of it going on at the same time. |
||
| private readonly ManualResetEventSlim _pendingParse = new ManualResetEventSlim(true); | ||
| private long _expectedParseVersion; | ||
| private long _expectedAnalysisVersion; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imported non-user files only get through AST analysis, do you actually get analysis unit here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand this comment.
PythonAnalyzer.AddModuleAnnotations adds annotations module to its Modules section. Just like for normal modules, you'd have to call .Analyze on the IPythonProjectEntry that is returned by AddModuleAnnotations.
Is there some other kind of analysis, that I am missing?