Skip to content

Commit

Permalink
Fix bug that does not have a test yet because I don't know yet how to…
Browse files Browse the repository at this point in the history
… manage references to packages and modules
  • Loading branch information
jecisc committed Dec 18, 2024
1 parent 3b21225 commit edb2b9e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
20 changes: 20 additions & 0 deletions src/Famix-Python-Importer-Tests/FamixPythonProject1Test.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,26 @@ FamixPythonProject1Test >> testReadAccessFromFunction [
self assert: (function accesses anySatisfy: [ :anAccess | anAccess variable = temporary ])
]

{ #category : 'tests - accesses' }
FamixPythonProject1Test >> testReadAccessFromImportedEntityWithNamespace [

| global module access |
self skip. "Cannot resolve this yet"
global := self globalVariableNamed: 'NameOfSubpackageOrClass'.
module := self moduleNamed: 'moduleAtRoot6'.

access := global incomingAccesses detect: [ :anAccess | anAccess accessor = module ].

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 >> testReadAccessFromImportedGlobalWithNamespace [

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ FamixPythonImportedAccessOrReferenceResolvable >> import: anObject [
{ #category : 'resolution' }
FamixPythonImportedAccessOrReferenceResolvable >> resolveInScope: aScope currentEntity: currentEntity [

import importedEntity name = identifier ifTrue: [ ^ self entity: import importedEntity ].

^ (import importedEntity definedEntitiesNamed: identifier ofKinds: {
FamixPythonClass.
FamixPythonFunction.
Expand Down
2 changes: 1 addition & 1 deletion src/Famix-Python-Importer/FamixPythonImporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FamixPythonImporter >> importFileReference: aFileReference [
FamixPythonImporter >> importPythonFile: aFileReference [

('Importing ' , aFileReference pathString) traceCr.
"(aFileReference basename = #'moduleImportingMultipleItems.py') ifTrue: [ 1halt ]."
"(aFileReference basename = #'moduleAtRoot6.py') ifTrue: [ 1halt ]."
(PythonParser parseFileWithErrors: aFileReference) acceptVisitor: visitor
]

Expand Down
10 changes: 6 additions & 4 deletions src/Famix-Python-Importer/FamixPythonImporterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,12 @@ FamixPythonImporterVisitor >> visitFieldAccessExpression: aFieldAccessExpression
self currentEntity allEffectiveSimpleImports
detect: [ :import |
| importPath |
importPath := (import hasAlias
ifTrue: [ import alias ]
ifFalse: [ importPaths at: import ]) , '.'.
(source beginsWith: importPath) and: [ ((source withoutPrefix: importPath) includes: $.) not ] ]
importPath := import hasAlias
ifTrue: [ import alias ]
ifFalse: [ importPaths at: import ].
source = importPath or: [
importPath := importPath , '.'.
(source beginsWith: importPath) and: [ ((source withoutPrefix: importPath) includes: $.) not ] ] ]
ifFound: [ :import |
self
resolve: ((FamixPythonImportedAccessOrReferenceResolvable identifier: aFieldAccessExpression name import: import)
Expand Down

0 comments on commit edb2b9e

Please sign in to comment.