mirror of
https://github.com/github/semantic.git
synced 2024-12-28 01:11:52 +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
|
||||
identifier :: Assignment
|
||||
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier <$> (name <$> source))
|
||||
<|> makeQualifiedIdentifier <$> symbol Attribute <*> children (attribute <|> identifierPair)
|
||||
<|> makeQualifiedIdentifier <$> symbol DottedName <*> children (some identifier')
|
||||
<|> symbol DottedName *> children identifier
|
||||
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
|
||||
makeQualifiedIdentifier loc xs = makeTerm loc (Syntax.Identifier (qualifiedName xs))
|
||||
|
||||
|
@ -34,10 +34,15 @@ spec = parallel $ do
|
||||
]
|
||||
env `shouldBe` expectedEnv
|
||||
|
||||
it "subclasses" $ do
|
||||
res <- evaluate' "subclass.py"
|
||||
fst res `shouldBe` Right (injValue (String "\"bar\""))
|
||||
|
||||
where
|
||||
addr = Address . Precise
|
||||
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
|
||||
[ fixtures <> entry
|
||||
, 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)+}
|
||||
(Empty))
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Integer)+}
|
||||
{+(Empty)+})+})
|
||||
|
4
test/fixtures/python/call.diffB-A.txt
vendored
4
test/fixtures/python/call.diffB-A.txt
vendored
@ -14,6 +14,8 @@
|
||||
{+(Identifier)+}
|
||||
(Empty))
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Integer)-}
|
||||
{-(Empty)-})-})
|
||||
|
4
test/fixtures/python/call.parseB.txt
vendored
4
test/fixtures/python/call.parseB.txt
vendored
@ -12,6 +12,8 @@
|
||||
(Identifier)
|
||||
(Empty))
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Integer)
|
||||
(Empty)))
|
||||
|
24
test/fixtures/python/import-graph/main.json
vendored
24
test/fixtures/python/import-graph/main.json
vendored
@ -269,8 +269,10 @@
|
||||
22
|
||||
]
|
||||
},
|
||||
"symbol": "os.getcwd",
|
||||
"targets": []
|
||||
"symbol": "getcwd",
|
||||
"targets": [
|
||||
"os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -283,8 +285,10 @@
|
||||
31
|
||||
]
|
||||
},
|
||||
"symbol": "np.array",
|
||||
"targets": []
|
||||
"symbol": "array",
|
||||
"targets": [
|
||||
"np"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -297,8 +301,10 @@
|
||||
20
|
||||
]
|
||||
},
|
||||
"symbol": "x.sum",
|
||||
"targets": []
|
||||
"symbol": "sum",
|
||||
"targets": [
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -311,8 +317,10 @@
|
||||
19
|
||||
]
|
||||
},
|
||||
"symbol": "x.sum",
|
||||
"targets": []
|
||||
"symbol": "sum",
|
||||
"targets": [
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
|
8
test/fixtures/python/with.diffA-B.txt
vendored
8
test/fixtures/python/with.diffA-B.txt
vendored
@ -25,7 +25,9 @@
|
||||
{+(Let
|
||||
{+(Empty)+}
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Identifier)+}
|
||||
{+(TextElement)+}
|
||||
{+(Identifier)+}
|
||||
@ -34,7 +36,9 @@
|
||||
{+(Let
|
||||
{+(Empty)+}
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Identifier)+}
|
||||
{+(TextElement)+}
|
||||
{+(Identifier)+}
|
||||
|
8
test/fixtures/python/with.diffB-A.txt
vendored
8
test/fixtures/python/with.diffB-A.txt
vendored
@ -25,7 +25,9 @@
|
||||
{-(Let
|
||||
{-(Empty)-}
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Identifier)-}
|
||||
{-(TextElement)-}
|
||||
{-(Identifier)-}
|
||||
@ -34,7 +36,9 @@
|
||||
{-(Let
|
||||
{-(Empty)-}
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Identifier)-}
|
||||
{-(TextElement)-}
|
||||
{-(Identifier)-}
|
||||
|
8
test/fixtures/python/with.parseB.txt
vendored
8
test/fixtures/python/with.parseB.txt
vendored
@ -12,7 +12,9 @@
|
||||
(Let
|
||||
(Empty)
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Identifier)
|
||||
(TextElement)
|
||||
(Identifier)
|
||||
@ -21,7 +23,9 @@
|
||||
(Let
|
||||
(Empty)
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Identifier)
|
||||
(TextElement)
|
||||
(Identifier)
|
||||
|
Loading…
Reference in New Issue
Block a user