From 05a308d2163608d6f31c2da3a3eaca67c8c5a592 Mon Sep 17 00:00:00 2001 From: tokyRT Date: Thu, 6 Nov 2025 16:14:58 +0100 Subject: [PATCH 1/5] add ressources for test cases --- .../examples/project1/src/moduleAtRoot13.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/resources/examples/project1/src/moduleAtRoot13.py b/resources/examples/project1/src/moduleAtRoot13.py index daecf2d..8855626 100644 --- a/resources/examples/project1/src/moduleAtRoot13.py +++ b/resources/examples/project1/src/moduleAtRoot13.py @@ -190,3 +190,24 @@ def function_with_keyword_argument(arg0, arg1=10): variableToAccessInKeywordArgumentCallInParenthesis = 42 function_with_keyword_argument(1, arg1 = (variableToAccessInKeywordArgumentCallInParenthesis)) + + +def variable_to_access_in_array_slice_1(): + variableToAccessInArraySlice = 2 + my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + return my_array[:variableToAccessInArraySlice] + +def variable_to_access_in_array_slice_2(): + variableToAccessInArraySlice = 5 + my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + return my_array[1:variableToAccessInArraySlice] + +def variable_to_access_in_array_slice_3(): + variableToAccessInArraySlice = 2 + my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + return my_array[::variableToAccessInArraySlice] + +def variable_to_access_in_array_slice_with_parentheses(): + variableToAccessInArraySlice = 3 + my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + return my_array[1:(variableToAccessInArraySlice)] From 62d94b861f90d4e7bc30a9a8b50bc2a76a029231 Mon Sep 17 00:00:00 2001 From: tokyRT Date: Thu, 6 Nov 2025 16:46:58 +0100 Subject: [PATCH 2/5] add first test --- .../FamixPythonProject1Test.class.st | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index 7080fed..c68057b 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -5569,6 +5569,25 @@ FamixPythonProject1Test >> testReadAccessInANot [ self assert: (module accesses anySatisfy: [ :anAccess | anAccess variable = global ]) ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInArraySlice1 [ + + | global function access | + global := self globalVariableNamed: 'variableToAccessInArraySlice'. + function := self functionNamed: 'variable_to_access_in_array_slice_1'. + + access := (global 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 includes: global). + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testReadAccessInAssertStatement [ From cf723b7470e33f62b9b37ec3edfa0da3b43ab61d Mon Sep 17 00:00:00 2001 From: tokyRT Date: Thu, 6 Nov 2025 16:48:21 +0100 Subject: [PATCH 3/5] update tests ressources --- .../examples/project1/src/moduleAtRoot13.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/resources/examples/project1/src/moduleAtRoot13.py b/resources/examples/project1/src/moduleAtRoot13.py index 8855626..aa4a61d 100644 --- a/resources/examples/project1/src/moduleAtRoot13.py +++ b/resources/examples/project1/src/moduleAtRoot13.py @@ -191,23 +191,17 @@ def function_with_keyword_argument(arg0, arg1=10): variableToAccessInKeywordArgumentCallInParenthesis = 42 function_with_keyword_argument(1, arg1 = (variableToAccessInKeywordArgumentCallInParenthesis)) +variableToAccessInArraySlice = 5 +arrayToBeAccessedInSlice = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] def variable_to_access_in_array_slice_1(): - variableToAccessInArraySlice = 2 - my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - return my_array[:variableToAccessInArraySlice] + return arrayToBeAccessedInSlice[:variableToAccessInArraySlice] def variable_to_access_in_array_slice_2(): - variableToAccessInArraySlice = 5 - my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - return my_array[1:variableToAccessInArraySlice] + return arrayToBeAccessedInSlice[1:variableToAccessInArraySlice] def variable_to_access_in_array_slice_3(): - variableToAccessInArraySlice = 2 - my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - return my_array[::variableToAccessInArraySlice] + return arrayToBeAccessedInSlice[::variableToAccessInArraySlice] def variable_to_access_in_array_slice_with_parentheses(): - variableToAccessInArraySlice = 3 - my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - return my_array[1:(variableToAccessInArraySlice)] + return arrayToBeAccessedInSlice[1:(variableToAccessInArraySlice)] From 18c84db0e5fcfec5b176aa68339b1aa25bed11c1 Mon Sep 17 00:00:00 2001 From: tokyRT Date: Thu, 6 Nov 2025 16:51:56 +0100 Subject: [PATCH 4/5] test: add more test cases for access in array slice --- .../FamixPythonProject1Test.class.st | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st index c68057b..495e321 100644 --- a/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st +++ b/src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st @@ -5588,6 +5588,63 @@ FamixPythonProject1Test >> testReadAccessInArraySlice1 [ self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = global ]) ] +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInArraySlice2 [ + + | global function access | + global := self globalVariableNamed: 'variableToAccessInArraySlice'. + function := self functionNamed: 'variable_to_access_in_array_slice_2'. + + access := (global 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 includes: global). + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInArraySlice3 [ + + | global function access | + global := self globalVariableNamed: 'variableToAccessInArraySlice'. + function := self functionNamed: 'variable_to_access_in_array_slice_3'. + + access := (global 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 includes: global). + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + +{ #category : 'tests - accesses' } +FamixPythonProject1Test >> testReadAccessInArraySliceWithParentheses [ + + | global function access | + global := self globalVariableNamed: 'variableToAccessInArraySlice'. + function := self functionNamed: 'variable_to_access_in_array_slice_with_parentheses'. + + access := (global 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 includes: global). + self assert: access variable equals: global. + self deny: access isWrite. + self assert: access isRead. + self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = global ]) +] + { #category : 'tests - accesses' } FamixPythonProject1Test >> testReadAccessInAssertStatement [ From d0a1f26c09f7a43edd772579edf531a4bf0ca050 Mon Sep 17 00:00:00 2001 From: tokyRT Date: Fri, 7 Nov 2025 10:26:06 +0100 Subject: [PATCH 5/5] create read access inside array slice --- .../FamixPythonVisitor.class.st | 6 ++++++ .../FamixTSNodeWrapper.extension.st | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Famix-Python-Importer/FamixPythonVisitor.class.st b/src/Famix-Python-Importer/FamixPythonVisitor.class.st index b4f1dd4..9329e16 100644 --- a/src/Famix-Python-Importer/FamixPythonVisitor.class.st +++ b/src/Famix-Python-Importer/FamixPythonVisitor.class.st @@ -1524,6 +1524,12 @@ FamixPythonVisitor >> visitReturnStatement: aNode [ ^ self visitChildren: aNode ] +{ #category : 'visiting - visitChildren' } +FamixPythonVisitor >> visitSlice: aNode [ + + ^ self visitChildren: aNode +] + { #category : 'visiting - visitChildren' } FamixPythonVisitor >> visitString: aStringNode [ " diff --git a/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st b/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st index 830e65e..d4b6a8f 100644 --- a/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st +++ b/src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st @@ -12,12 +12,17 @@ FamixTSNodeWrapper >> isAccessOrReferenceNode [ "I should return true if an Identifier node represent an access or a reference." (self parent type = #attribute and: [ self parent isInCall ]) ifTrue: [ ^ true ]. - + (self isInField: #value ofParentOfType: #keyword_argument) ifTrue: [ ^ true ]. - ^ #( 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 tuple expression_list) includes: self parent type + "this is for the case where a slice contains variable wrapped in parenthesis + e.g arr[1:(end)] or arr[1:(((end)))]" + (self parent type = #parenthesized_expression and: [ (self parentOfType: #slice) isNotNil ]) ifTrue: [ ^ true ]. + + ^ #( 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 + tuple expression_list slice ) includes: self parent type ] { #category : '*Famix-Python-Importer' }