1
1
mirror of https://github.com/github/semantic.git synced 2024-12-28 17:32:05 +03:00

Merge pull request #1666 from github/fix-python-member-call

Fix Python method calls.
This commit is contained in:
Patrick Thomson 2018-03-22 16:34:42 -04:00 committed by GitHub
commit 75bf3bebe4
10 changed files with 58 additions and 21 deletions

View File

@ -340,12 +340,9 @@ yield = makeTerm <$> symbol Yield <*> (Statement.Yield <$> children (term ( expr
-- Identifiers and qualified identifiers (e.g. `a.b.c`) from things like DottedName and Attribute -- Identifiers and qualified identifiers (e.g. `a.b.c`) from things like DottedName and Attribute
identifier :: Assignment identifier :: Assignment
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier <$> (name <$> source)) identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier <$> (name <$> source))
<|> makeQualifiedIdentifier <$> symbol Attribute <*> children (attribute <|> identifierPair)
<|> makeQualifiedIdentifier <$> symbol DottedName <*> children (some identifier') <|> makeQualifiedIdentifier <$> symbol DottedName <*> children (some identifier')
<|> symbol DottedName *> children identifier <|> symbol DottedName *> children identifier
where where
attribute = (\a b -> a <> [b]) <$> (symbol Attribute *> children (attribute <|> identifierPair)) <*> identifier'
identifierPair = (\a b -> [a, b]) <$> identifier' <*> identifier'
identifier' = (symbol Identifier <|> symbol Identifier') *> source identifier' = (symbol Identifier <|> symbol Identifier') *> source
makeQualifiedIdentifier loc xs = makeTerm loc (Syntax.Identifier (qualifiedName xs)) makeQualifiedIdentifier loc xs = makeTerm loc (Syntax.Identifier (qualifiedName xs))

View File

@ -34,10 +34,15 @@ spec = parallel $ do
] ]
env `shouldBe` expectedEnv env `shouldBe` expectedEnv
it "subclasses" $ do
res <- evaluate' "subclass.py"
fst res `shouldBe` Right (injValue (String "\"bar\""))
where where
addr = Address . Precise addr = Address . Precise
fixtures = "test/fixtures/python/analysis/" fixtures = "test/fixtures/python/analysis/"
evaluate entry = snd . fst . fst . fst . fst <$> evaluate entry = snd <$> evaluate' entry
evaluate' entry = fst . fst . fst . fst <$>
evaluateFiles pythonParser evaluateFiles pythonParser
[ fixtures <> entry [ fixtures <> entry
, fixtures <> "a.py" , fixtures <> "a.py"

View File

@ -0,0 +1,9 @@
class Foo():
def dang():
return "foo"
class Bar():
def dang():
return "bar"
Bar.dang()

View File

@ -14,6 +14,8 @@
{+(Identifier)+} {+(Identifier)+}
(Empty)) (Empty))
{+(Call {+(Call
{+(Identifier)+} {+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Integer)+} {+(Integer)+}
{+(Empty)+})+}) {+(Empty)+})+})

View File

@ -14,6 +14,8 @@
{+(Identifier)+} {+(Identifier)+}
(Empty)) (Empty))
{-(Call {-(Call
{-(Identifier)-} {-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Integer)-} {-(Integer)-}
{-(Empty)-})-}) {-(Empty)-})-})

View File

@ -12,6 +12,8 @@
(Identifier) (Identifier)
(Empty)) (Empty))
(Call (Call
(Identifier) (MemberAccess
(Identifier)
(Identifier))
(Integer) (Integer)
(Empty))) (Empty)))

View File

@ -269,8 +269,10 @@
22 22
] ]
}, },
"symbol": "os.getcwd", "symbol": "getcwd",
"targets": [] "targets": [
"os"
]
}, },
{ {
"span": { "span": {
@ -283,8 +285,10 @@
31 31
] ]
}, },
"symbol": "np.array", "symbol": "array",
"targets": [] "targets": [
"np"
]
}, },
{ {
"span": { "span": {
@ -297,8 +301,10 @@
20 20
] ]
}, },
"symbol": "x.sum", "symbol": "sum",
"targets": [] "targets": [
"x"
]
}, },
{ {
"span": { "span": {
@ -311,8 +317,10 @@
19 19
] ]
}, },
"symbol": "x.sum", "symbol": "sum",
"targets": [] "targets": [
"x"
]
}, },
{ {
"span": { "span": {

View File

@ -25,7 +25,9 @@
{+(Let {+(Let
{+(Empty)+} {+(Empty)+}
{+(Call {+(Call
{+(Identifier)+} {+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Identifier)+} {+(Identifier)+}
{+(TextElement)+} {+(TextElement)+}
{+(Identifier)+} {+(Identifier)+}
@ -34,7 +36,9 @@
{+(Let {+(Let
{+(Empty)+} {+(Empty)+}
{+(Call {+(Call
{+(Identifier)+} {+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Identifier)+} {+(Identifier)+}
{+(TextElement)+} {+(TextElement)+}
{+(Identifier)+} {+(Identifier)+}

View File

@ -25,7 +25,9 @@
{-(Let {-(Let
{-(Empty)-} {-(Empty)-}
{-(Call {-(Call
{-(Identifier)-} {-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Identifier)-} {-(Identifier)-}
{-(TextElement)-} {-(TextElement)-}
{-(Identifier)-} {-(Identifier)-}
@ -34,7 +36,9 @@
{-(Let {-(Let
{-(Empty)-} {-(Empty)-}
{-(Call {-(Call
{-(Identifier)-} {-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Identifier)-} {-(Identifier)-}
{-(TextElement)-} {-(TextElement)-}
{-(Identifier)-} {-(Identifier)-}

View File

@ -12,7 +12,9 @@
(Let (Let
(Empty) (Empty)
(Call (Call
(Identifier) (MemberAccess
(Identifier)
(Identifier))
(Identifier) (Identifier)
(TextElement) (TextElement)
(Identifier) (Identifier)
@ -21,7 +23,9 @@
(Let (Let
(Empty) (Empty)
(Call (Call
(Identifier) (MemberAccess
(Identifier)
(Identifier))
(Identifier) (Identifier)
(TextElement) (TextElement)
(Identifier) (Identifier)