diff --git a/resources/examples/project1/src/moduleAtRoot13.py b/resources/examples/project1/src/moduleAtRoot13.py index a50ff26..5c4cacb 100644 --- a/resources/examples/project1/src/moduleAtRoot13.py +++ b/resources/examples/project1/src/moduleAtRoot13.py @@ -174,3 +174,10 @@ def function_to_invoke_in_list_splat(indices): indices = [0, 2, 4, 6, 8] var = [*function_to_invoke_in_list_splat(slice, indices[:-1], indices[1:])] + +variableToAccessInTuple = 7 +aTuple = (1, 2, variableToAccessInTuple, 4) + +def variable_to_access_in_tuple_return(): + variableToAccessInTuple = 8 + return 0, variableToAccessInTuple \ No newline at end of file diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index ed627f0..5337c94 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -5784,6 +5784,28 @@ FamixPythonProject1Test >> testReadAccessInDictionarySplat [ self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ]) ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInExpressionList [ + "same as tuple but it becomes an expression_list node in some cases like in a return: + def func(): + return a, b + " + | local function access | + local := self localVariableNamed: 'variableToAccessInTuple'. + function := self functionNamed: 'variable_to_access_in_tuple_return'. + + access := (local incomingAccesses select: [ :anAccess | anAccess accessor = function ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ]. + + self assert: access class equals: FamixPythonAccess. + self assert: access source equals: function. + self assert: access accessor equals: function. + self assert: access target equals: local. + self assert: access variable equals: local. + self deny: access isWrite. + self assert: access isRead. + self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = local ]) +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testReadAccessInGeneratorExpression [ @@ -5967,6 +5989,25 @@ FamixPythonProject1Test >> testReadAccessInPair [ self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ]) ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInTuple [ + + | global module access | + global := self globalVariableNamed: 'variableToAccessInTuple'. + module := self moduleNamed: 'moduleAtRoot13'. + + access := (global incomingAccesses select: [ :anAccess | anAccess accessor = module ]) detectMax: [ :anAccess | anAccess sourceAnchor startPos ]. + + self assert: access class equals: FamixPythonAccess. + self assert: access source equals: module. + self assert: access accessor equals: module. + self assert: access target equals: global. + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testReadAccessInTypedDefaultParameter [ diff --git a/src/Famix-Python-Importer/FamixPythonVisitor.class.st b/src/Famix-Python-Importer/FamixPythonVisitor.class.st index 2fe27e2..d12b508 100644 --- a/src/Famix-Python-Importer/FamixPythonVisitor.class.st +++ b/src/Famix-Python-Importer/FamixPythonVisitor.class.st @@ -1028,6 +1028,12 @@ FamixPythonVisitor >> visitEscapeSequence: aNode [ ^ self visitChildren: aNode ] +{ #category : 'visiting - visitChildren' } +FamixPythonVisitor >> visitExpressionList: aNode [ + + ^ self visitChildren: aNode +] + { #category : 'visiting - visitChildren' } FamixPythonVisitor >> visitExpressionStatement: aNode [ diff --git a/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st b/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st index 3e87d73..ad73445 100644 --- a/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st +++ b/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st @@ -15,7 +15,7 @@ FamixTSNodeWrapper >> isAccessOrReferenceNode [ ^ #( elif_clause list argument_list return_statement lambda if_statement comparison_operator binary_operator assignment not_operator expression_statement augmented_assignment unary_operator boolean_operator pair list_splat default_parameter dictionary_splat #if_clause #for_in_clause generator_expression - list_comprehension dictionary_comprehension string_content interpolation subscript) includes: self parent type + list_comprehension dictionary_comprehension string_content interpolation subscript tuple expression_list) includes: self parent type ] { #category : '*Famix-Python-Importer' }