Skip to content

Commit a2fb7ab

Browse files
author
JMLF
committed
Merge fc3eed5
2 parents 3d84b05 + fc3eed5 commit a2fb7ab

File tree

5 files changed

+67
-12
lines changed

5 files changed

+67
-12
lines changed

resources/examples/project1/src/moduleAtRoot15.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Some examples of temporary variables usage. Note everything is here.
1+
# Some examples of temporary variables usage. Not everything is here.
22

33
print(localVarInGeneratorExpression for localVarInGeneratorExpression in range(5))
44

resources/examples/project1/src/moduleAtRoot4.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
moduleAtRootSpaceString = ' '
1010

1111
numpy.random.random(50000)**2
12+
13+
14+
# next two lines are for a regression test
15+
from tensorflow.python.ops import variable_scope
16+
17+
variable_scope.variable_scope(moduleAtRootSpaceString or "rnn_decoder")

src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,8 +2327,6 @@ FamixPythonProject1Test >> testFunctionSourceAnchor [
23272327
FamixPythonProject1Test >> testFunctionTypedDefaultParameter [
23282328
23292329
| function parameter |
2330-
self skip.
2331-
self flag: #todo. "Manage assertions on types."
23322330
function := self functionNamed: 'function_with_typed_default_parameter'.
23332331
parameter := self parameterNamed: 'default_typed_parameter'.
23342332
@@ -2340,14 +2338,32 @@ FamixPythonProject1Test >> testFunctionTypedDefaultParameter [
23402338
self assert: parameter parentBehaviouralEntity equals: function.
23412339
self assert: parameter hasDefaultValue.
23422340
self deny: parameter isListSplat.
2343-
self deny: parameter isDictionarySplat
2341+
self deny: parameter isDictionarySplat.
2342+
2343+
2344+
self flag: #todo "Manage assertions on types."
23442345
]
23452346
23462347
{ #category : 'tests - parameters' }
23472348
FamixPythonProject1Test >> testFunctionTypedParameter [
23482349
2349-
self flag: #todo.
2350-
self skip
2350+
| function parameter |
2351+
function := self functionNamed: 'function_with_typed_parameter'.
2352+
parameter := self parameterNamed: 'typed_parameter'.
2353+
2354+
self assert: function parameters size equals: 1.
2355+
self assert: function keywordSeparatorPosition equals: nil.
2356+
self assert: function positionalSeparatorPosition equals: nil.
2357+
self assertCollection: function parameters hasSameElements: { parameter }.
2358+
self assert: parameter name equals: 'typed_parameter'.
2359+
self deny: parameter isStub.
2360+
self assert: parameter class equals: FamixPythonParameter.
2361+
self assert: parameter parentBehaviouralEntity equals: function.
2362+
self deny: parameter hasDefaultValue.
2363+
self deny: parameter isListSplat.
2364+
self deny: parameter isDictionarySplat.
2365+
2366+
self flag: #todo. "Add assertions on type because we currently only have assertions on the existance of the parameter."
23512367
]
23522368
23532369
{ #category : 'tests - functions' }
@@ -3205,6 +3221,21 @@ FamixPythonProject1Test >> testInvocationToUnknowEntityOfSameNameAsUnknowPackage
32053221
self assert: unknowFunction isStub
32063222
]
32073223
3224+
{ #category : 'tests' }
3225+
FamixPythonProject1Test >> testInvocationToUnknowEntityOfSameNameAsUnknowPackage2 [
3226+
"Regression test"
3227+
3228+
| unknowFunction |
3229+
"I get the one without children to have the bottom most entity of this name since it should be in an entity of the same name."
3230+
unknowFunction := self model entities detect: [ :entity |
3231+
entity class = FamixPythonUnknownEntity and: [ entity name = 'variable_scope' and: [ entity childEntities isEmpty ] ] ].
3232+
3233+
self assert: unknowFunction name equals: 'variable_scope'.
3234+
self assert: unknowFunction parentPackage name equals: 'variable_scope'.
3235+
self deny: unknowFunction identicalTo: unknowFunction parentPackage.
3236+
self assert: unknowFunction isStub
3237+
]
3238+
32083239
{ #category : 'tests - invocations' }
32093240
FamixPythonProject1Test >> testInvocationsThatCannotBeResolved [
32103241
"I created a file with a lot of invocations that cannot be resolved and we will ensure we do not create any invocation for them."

src/Famix-Python-Importer/FamixPythonVisitor.class.st

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ FamixPythonVisitor >> manageAttributeAsCallReceiver: aNode [
389389
expectedKind: {
390390
FamixPythonFunction.
391391
FamixPythonClass };
392-
notFoundReplacementEntity: [ :unresolved :currentEntity | "This one can be a function or a class"
392+
notFoundReplacementEntity: [ :unresolved :currentEntity |
393+
"This one can be a function or a class"
393394
(self ensureStubUnknownEntityNamed: unresolved identifier)
394395
parentPackage: import importedEntity;
395396
yourself ];
@@ -402,10 +403,7 @@ FamixPythonVisitor >> manageAttributeAsCallReceiver: aNode [
402403
ifFound: [ :import |
403404
^ self
404405
resolve: ((FamixPythonDependencyFromImportedEntityResolvable identifier: identifier import: import)
405-
notFoundReplacementEntity: [ :unresolved :currentEntity |
406-
(self ensureStubUnknownEntityNamed: unresolved identifier)
407-
parentPackage: unresolved import importedEntity;
408-
yourself ];
406+
notFoundReplacementEntity: [ :unresolved :currentEntity | self ensureStubUnknownEntityNamed: unresolved identifier in: unresolved import importedEntity ];
409407
yourself)
410408
foundAction: [ :result :currentEntity | self createAssociationsForFunctionCallNode: (aNode parentOfType: #call) forResult: result in: currentEntity ] ].
411409

@@ -1654,6 +1652,18 @@ FamixPythonVisitor >> visitTuplePattern: aNode [
16541652
^ self visitChildren: aNode
16551653
]
16561654

1655+
{ #category : 'visiting' }
1656+
FamixPythonVisitor >> visitTypedDefaultParameter: aNode [
1657+
"
1658+
TODO
1659+
"
1660+
1661+
self flag: #todo. "Manage typing"
1662+
(self visit: aNode _name) attributeAt: #hasDefaultValue put: true.
1663+
self visit: aNode _type.
1664+
self visit: aNode _value
1665+
]
1666+
16571667
{ #category : 'visiting - visitChildren' }
16581668
FamixPythonVisitor >> visitUnaryOperator: aNode [
16591669
"

src/Famix-Python-Importer/FamixTSNodeWrapper.extension.st

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,15 @@ FamixTSNodeWrapper >> isParameterDeclaration [
9090
"In a default parameter, it represent the parameter if it's in the name field."
9191
"def f(arg=3):"
9292
(self parent type = #default_parameter and: [ self parent _name = self ]) ifTrue: [ ^ true ].
93-
93+
94+
"Typed parameter
95+
def f(arg: int):"
96+
(self parent type = #typed_parameter) ifTrue: [ ^ true].
97+
98+
"Typed default parameter
99+
def (arg: int = 5):"
100+
(self parent type = #typed_default_parameter) ifTrue: [ ^true ].
101+
94102
^ false
95103
]
96104

0 commit comments

Comments
 (0)