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:
commit
75bf3bebe4
@ -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))
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
9
test/fixtures/python/analysis/subclass.py
vendored
Normal file
9
test/fixtures/python/analysis/subclass.py
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class Foo():
|
||||||
|
def dang():
|
||||||
|
return "foo"
|
||||||
|
|
||||||
|
class Bar():
|
||||||
|
def dang():
|
||||||
|
return "bar"
|
||||||
|
|
||||||
|
Bar.dang()
|
4
test/fixtures/python/call.diffA-B.txt
vendored
4
test/fixtures/python/call.diffA-B.txt
vendored
@ -14,6 +14,8 @@
|
|||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
(Empty))
|
(Empty))
|
||||||
{+(Call
|
{+(Call
|
||||||
{+(Identifier)+}
|
{+(MemberAccess
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(Identifier)+})+}
|
||||||
{+(Integer)+}
|
{+(Integer)+}
|
||||||
{+(Empty)+})+})
|
{+(Empty)+})+})
|
||||||
|
4
test/fixtures/python/call.diffB-A.txt
vendored
4
test/fixtures/python/call.diffB-A.txt
vendored
@ -14,6 +14,8 @@
|
|||||||
{+(Identifier)+}
|
{+(Identifier)+}
|
||||||
(Empty))
|
(Empty))
|
||||||
{-(Call
|
{-(Call
|
||||||
{-(Identifier)-}
|
{-(MemberAccess
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(Identifier)-})-}
|
||||||
{-(Integer)-}
|
{-(Integer)-}
|
||||||
{-(Empty)-})-})
|
{-(Empty)-})-})
|
||||||
|
4
test/fixtures/python/call.parseB.txt
vendored
4
test/fixtures/python/call.parseB.txt
vendored
@ -12,6 +12,8 @@
|
|||||||
(Identifier)
|
(Identifier)
|
||||||
(Empty))
|
(Empty))
|
||||||
(Call
|
(Call
|
||||||
(Identifier)
|
(MemberAccess
|
||||||
|
(Identifier)
|
||||||
|
(Identifier))
|
||||||
(Integer)
|
(Integer)
|
||||||
(Empty)))
|
(Empty)))
|
||||||
|
24
test/fixtures/python/import-graph/main.json
vendored
24
test/fixtures/python/import-graph/main.json
vendored
@ -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": {
|
||||||
|
8
test/fixtures/python/with.diffA-B.txt
vendored
8
test/fixtures/python/with.diffA-B.txt
vendored
@ -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)+}
|
||||||
|
8
test/fixtures/python/with.diffB-A.txt
vendored
8
test/fixtures/python/with.diffB-A.txt
vendored
@ -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)-}
|
||||||
|
8
test/fixtures/python/with.parseB.txt
vendored
8
test/fixtures/python/with.parseB.txt
vendored
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user