Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions driver/normalizer/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var AnnotationRules = On(Any).Self(
// FIXME: the FunctionDeclarationReceiver is not set for methods; it should be taken from the parent
// Type node Token (2 levels up) but the SDK doesn't allow this
// TODO: create an issue for the SDK
On(HasInternalType(pyast.FunctionDef)).Roles(FunctionDeclaration, FunctionDeclarationName).Children(
On(HasInternalType(pyast.FunctionDef)).Roles(FunctionDeclaration, FunctionDeclarationName, SimpleIdentifier).Children(
On(HasInternalType("FunctionDef.body")).Roles(FunctionDeclarationBody),
// FIXME: change to FunctionDeclarationArgumentS once the PR has been merged
On(HasInternalType("arguments")).Roles(FunctionDeclarationArgument).Children(
Expand Down Expand Up @@ -194,7 +194,7 @@ var AnnotationRules = On(Any).Self(
On(HasInternalRole("func")).Self(On(HasInternalRole("id"))).Roles(CallCallee),
On(HasInternalRole("func")).Self(On(HasInternalRole("attr"))).Roles(CallCallee),
On(HasInternalRole("func")).Self(On(HasInternalType(pyast.Attribute))).Children(
On(HasInternalRole("id")).Roles(CallReceiver),
On(HasInternalRole("id")).Roles(CallReceiver, SimpleIdentifier),
),
),

Expand Down Expand Up @@ -280,8 +280,8 @@ var AnnotationRules = On(Any).Self(
On(HasInternalType(pyast.IfExp)).Roles(If),
On(HasInternalType(pyast.Import)).Roles(ImportDeclaration),
On(HasInternalType(pyast.ImportFrom)).Roles(ImportDeclaration),
On(HasInternalType(pyast.Alias)).Roles(ImportAlias),
On(HasInternalType(pyast.ClassDef)).Roles(TypeDeclaration).Children(
On(HasInternalType(pyast.Alias)).Roles(ImportAlias, SimpleIdentifier),
On(HasInternalType(pyast.ClassDef)).Roles(TypeDeclaration, SimpleIdentifier).Children(
On(HasInternalType("ClassDef.body")).Roles(TypeDeclarationBody),
On(HasInternalType("ClassDef.bases")).Roles(TypeDeclarationBases),
),
Expand Down Expand Up @@ -313,7 +313,7 @@ var AnnotationRules = On(Any).Self(
),
// Repr already comes as a Call \o/
// Print as a function too.
On(HasInternalType(pyast.Print)).Roles(Call, CallCallee).Children(
On(HasInternalType(pyast.Print)).Roles(Call, CallCallee, SimpleIdentifier).Children(
On(HasInternalRole("dest")).Roles(CallPositionalArgument),
On(HasInternalRole("nl")).Roles(CallPositionalArgument),
On(HasInternalRole("values")).Roles(CallPositionalArgument).Children(
Expand Down Expand Up @@ -346,6 +346,5 @@ var AnnotationRules = On(Any).Self(
On(HasInternalRole("left")).Roles(BinaryExpressionLeft),
),
),

),
)
10 changes: 5 additions & 5 deletions tests/classdef.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "Animal"
. . . StartPosition: {
. . . . Offset: 0
Expand All @@ -28,7 +28,7 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: FunctionDef {
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . . . . . TOKEN "__init__"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 0
Expand Down Expand Up @@ -165,7 +165,7 @@ Module {
. . . . . . . }
. . . . . . }
. . . . . . 1: FunctionDef {
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . . . . . TOKEN "method"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 0
Expand Down Expand Up @@ -265,7 +265,7 @@ Module {
. . . . . . . }
. . . . . . }
. . . . . . 2: FunctionDef {
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . . . . . TOKEN "a"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 0
Expand Down Expand Up @@ -386,7 +386,7 @@ Module {
. . . . . . . }
. . . . . . }
. . . . . . 3: FunctionDef {
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . . . . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . . . . . TOKEN "a"
. . . . . . . StartPosition: {
. . . . . . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/classdef_inheritance.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "Dog"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -60,7 +60,7 @@ Module {
. . . }
. . }
. . 1: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "RobotDog"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/classdef_metaclass_py2.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "MySingleton"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/classdef_metaclass_py3.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "MySingleton"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -70,7 +70,7 @@ Module {
. . . }
. . }
. . 1: ClassDef {
. . . Roles: TypeDeclaration
. . . Roles: TypeDeclaration,SimpleIdentifier
. . . TOKEN "MySingleton"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/functiondef_annotated.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/functiondef_decorated.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -76,7 +76,7 @@ Module {
. . . }
. . }
. . 1: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/functiondef_defaultparams.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/functiondef_docstring.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/functiondef_kwarg.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -94,7 +94,7 @@ Module {
. . . }
. . }
. . 1: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someVarMapFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/functiondef_simple.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -118,7 +118,7 @@ Module {
. . . }
. . }
. . 1: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someGen"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/functiondef_vararg.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "someFunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
12 changes: 6 additions & 6 deletions tests/import.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "sys"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
Expand All @@ -53,14 +53,14 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "sys"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
. . . . . . . }
. . . . . . }
. . . . . . 1: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "os"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
Expand Down Expand Up @@ -89,7 +89,7 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "path"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
Expand Down Expand Up @@ -118,14 +118,14 @@ Module {
. . . . . }
. . . . . Children: {
. . . . . . 0: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "join"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
. . . . . . . }
. . . . . . }
. . . . . . 1: alias {
. . . . . . . Roles: ImportAlias
. . . . . . . Roles: ImportAlias,SimpleIdentifier
. . . . . . . TOKEN "exists"
. . . . . . . Properties: {
. . . . . . . . asname: <nil>
Expand Down
4 changes: 2 additions & 2 deletions tests/pass.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Module {
. . . }
. . }
. . 1: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "somefun"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -109,7 +109,7 @@ Module {
. . . }
. . }
. . 2: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "otherfun"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
4 changes: 2 additions & 2 deletions tests/print.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Module {
. }
. Children: {
. . 0: Print {
. . . Roles: Call,CallCallee
. . . Roles: Call,CallCallee,SimpleIdentifier
. . . TOKEN "print"
. . . StartPosition: {
. . . . Offset: 0
Expand Down Expand Up @@ -39,7 +39,7 @@ Module {
. . . }
. . }
. . 1: Print {
. . . Roles: Call,CallCallee
. . . Roles: Call,CallCallee,SimpleIdentifier
. . . TOKEN "print"
. . . StartPosition: {
. . . . Offset: 0
Expand Down
2 changes: 1 addition & 1 deletion tests/string_fstring.py.uast
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ Module {
. . . }
. . }
. . 7: FunctionDef {
. . . Roles: FunctionDeclaration,FunctionDeclarationName
. . . Roles: FunctionDeclaration,FunctionDeclarationName,SimpleIdentifier
. . . TOKEN "somefunc"
. . . StartPosition: {
. . . . Offset: 0
Expand Down