Fixed regression where "__class__" symbol (defined in PEP 3135) was not added implicitly to a function scope.

This commit is contained in:
Eric Traut 2020-08-25 15:29:16 -07:00
parent 41424cc28e
commit 14931faf4e
2 changed files with 8 additions and 1 deletions

View File

@ -417,6 +417,12 @@ export class Binder extends ParseTreeWalker {
this._createNewScope(ScopeType.Function, functionOrModuleScope, () => {
AnalyzerNodeInfo.setScope(node, this._currentScope!);
const enclosingClass = ParseTreeUtils.getEnclosingClass(node);
if (enclosingClass) {
// Add the implicit "__class__" symbol described in PEP 3135.
this._addBuiltInSymbolToCurrentScope('__class__', node, 'class');
}
this._deferBinding(() => {
// Create a start node for the function.
this._currentFlowNode = this._createStartFlowNode();

View File

@ -9,7 +9,8 @@ class Bar(Foo):
pass
class Bar2(Foo, metaclass=type):
pass
def my_method(self):
print(__class__)
# This should generate an error because only one metaclass is supported.
class Bar3(Foo, metaclass=type, metaclass=type):