1
1
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:
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
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))

View File

@ -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"

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)+}
(Empty))
{+(Call
{+(Identifier)+}
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Integer)+}
{+(Empty)+})+})

View File

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

View File

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

View File

@ -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": {

View File

@ -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)+}

View File

@ -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)-}

View File

@ -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)