8000 Filter class members · github/semantic@df1e8cd · GitHub
[go: up one dir, main page]

Skip to content
8000
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit df1e8cd

Browse files
committed
Filter class members
1 parent 6c7c398 commit df1e8cd

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

semantic-python/src/Language/Python/ScopeGraph.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ instance ToScopeGraph Py.ClassDefinition where
208208
for_ bindings $ \(node, statement) -> do
209209
if isInstanceMember statement then
210210
modify (Stack.addEdge (Stack.InstanceMembers "IM") node)
211+
else if isClassMember statement then
212+
modify (Stack.addEdge (Stack.ClassMembers "CM") node)
211213
else pure ()
212214
undefined
213215
res -> pure res
@@ -218,11 +220,28 @@ instance ToScopeGraph Py.ClassDefinition where
218220

219221
isInstanceMember :: (Py.SimpleStatement :+: Py.CompoundStatement) a -> Bool
220222
isInstanceMember statement = case statement of
221-
L1 _ -> False
223+
L1 (Py.SimpleStatement _) -> False
222224
R1 (Py.CompoundStatement compoundStatement) -> case compoundStatement of
223225
Prj (Py.FunctionDefinition {}) -> True
224226
_ -> False
225227

228+
isClassMember :: (Py.SimpleStatement :+: Py.CompoundStatement) a -> Bool
229+
isClassMember statement = case statement of
230+
L1 (Py.SimpleStatement simpleStatement) -> case simpleStatement of
231+
Prj (Py.ExpressionStatement _ expressions) -> all isAssignment expressions
232+
_ -> False
233+
R1 (Py.CompoundStatement compoundStatement) -> case compoundStatement of
234+
_ -> False
235+
236+
isAssignment :: (:+:)
237+
(Py.Expression :+: Py.Assignment)
238+
(Py.AugmentedAssignment :+: Py.Yield)
239+
a -> Bool
240+
isAssignment expressionStatement = case expressionStatement of
241+
Prj (Py.Assignment {}) -> True
242+
Prj (Py.AugmentedAssignment {}) -> True
243+
_ -> False
244+
226245
instance ToScopeGraph Py.ConcatenatedString where
227246
type FocalPoint Py.ConcatenatedString _ = Stack.Node
228247
scopeGraph = todo

0 commit comments

Comments
 (0)
0