This repository has been archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Handle named tuples #339
Merged
+1,096
−898
Merged
Handle named tuples #339
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
51da19c
Walk
381c930
Tests
993f8bd
Undo
99ee98a
Comments
d5774f3
PR feedback
80aabe1
Fix more
15a78e1
Update test
1c2b46d
Merge branch 'walk' into 15-2
134f76f
Basic named tuple annotation processing
649ebde
Test fix
1921f79
Introduce ability to return class definition
3f92897
Named tuple, part II
8e61522
Properly transfer tuple elements
ac07b7c
Fix AF message
74a60f1
Remove debug code
21aeea8
Merge branch 'master' of https://github.com/Microsoft/python-language…
37467e2
Fix slicing
c869f85
Add completion test
1abce37
Move GetIndex up
f33f680
Return Type when converting to class unknown builtin
aeff018
Use proper lock object
69c87fc
Merge branch 'master' of https://github.com/Microsoft/python-language…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalkerSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Python Tools for Visual Studio | ||
// Copyright(c) Microsoft Corporation | ||
// All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the License); you may not use | ||
// this file except in compliance with the License. You may obtain a copy of the | ||
// License at http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY | ||
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
// MERCHANTABILITY OR NON-INFRINGEMENT. | ||
// | ||
// See the Apache Version 2.0 License for specific language governing | ||
// permissions and limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.PythonTools.Analysis.Infrastructure; | ||
using Microsoft.PythonTools.Parsing.Ast; | ||
|
||
namespace Microsoft.PythonTools.Interpreter.Ast { | ||
/// <summary> | ||
/// Represents set of function body walkers. Functions are walked after | ||
/// all classes are collected. If function or property return type is unknown, | ||
/// it can be walked, and so on recursively, until return type is determined | ||
/// or there is nothing left to walk. | ||
/// </summary> | ||
class AstAnalysisFunctionWalkerSet { | ||
private readonly Dictionary<FunctionDefinition, AstAnalysisFunctionWalker> _functionWalkers | ||
= new Dictionary<FunctionDefinition, AstAnalysisFunctionWalker>(); | ||
|
||
public void Add(AstAnalysisFunctionWalker walker) | ||
=> _functionWalkers[walker.Target] = walker; | ||
|
||
public void ProcessSet() { | ||
// Do not use foreach since walker list is dynamically modified and walkers are removed | ||
// after processing. Handle __init__ and __new__ first so class variables are initialized. | ||
var constructors = _functionWalkers | ||
.Where(kvp => kvp.Key.Name == "__init__" || kvp.Key.Name == "__new__") | ||
.Select(c => c.Value) | ||
.ExcludeDefault() | ||
.ToArray(); | ||
|
||
foreach (var ctor in constructors) { | ||
ProcessWalker(ctor); | ||
} | ||
|
||
while (_functionWalkers.Count > 0) { | ||
var walker = _functionWalkers.First().Value; | ||
ProcessWalker(walker); | ||
} | ||
} | ||
|
||
public void ProcessFunction(FunctionDefinition fn) { | ||
if (_functionWalkers.TryGetValue(fn, out var w)) { | ||
ProcessWalker(w); | ||
} | ||
} | ||
|
||
private void ProcessWalker(AstAnalysisFunctionWalker walker) { | ||
// Remove walker before processing as to prevent reentrancy. | ||
_functionWalkers.Remove(walker.Target); | ||
walker.Walk(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Empty static method?
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.
Apparently it is called from DDG... Let's leave this alone until we decide fate of the DDG.