Skip to content

Commit 14db1a0

Browse files
arthaudfacebook-github-bot
authored andcommitted
Properly ignore decorators on class method calls
Summary: As titled. Reviewed By: dkgi Differential Revision: D30147034 fbshipit-source-id: f2d5fa9825e9a3b9dd0a9dc74897ac98302569be
1 parent 728e361 commit 14db1a0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

source/interprocedural/callGraph.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ let resolve_callees_ignoring_decorators ~resolution ~collapse_tito callee =
593593
| Expression.Name (Name.Attribute { base; attribute; _ }) -> (
594594
(* Resolve `base.attribute` by looking up the type of `base`. *)
595595
match resolve_ignoring_optional ~resolution base with
596-
| Type.Primitive class_name -> (
596+
| Type.Primitive class_name
597+
| Type.Parametric { name = "type"; parameters = [Single (Type.Primitive class_name)] } -> (
597598
GlobalResolution.class_definition global_resolution (Type.Primitive class_name)
598599
>>| Node.value
599600
>>| ClassSummary.attributes

source/interprocedural/test/callGraphTest.ml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,44 @@ let test_call_graph_of_define context =
13691369
targets = [`Method { Callable.class_name = "test.Foo"; method_name = "bar" }];
13701370
}) );
13711371
];
1372+
assert_call_graph_of_define
1373+
~source:
1374+
{|
1375+
from typing import Callable, TypeVar
1376+
from pyre_extensions import ParameterSpecification
1377+
1378+
_T = TypeVar("_T")
1379+
_TParams = ParameterSpecification("_TParams")
1380+
1381+
class Timer:
1382+
def __call__(self, func: Callable[_TParams, _T]) -> Callable[_TParams, _T]:
1383+
return func
1384+
1385+
def timer(name: str) -> Timer:
1386+
return Timer()
1387+
1388+
class Foo:
1389+
@classmethod
1390+
@timer("bar")
1391+
def bar(cls, x: int) -> None:
1392+
pass
1393+
1394+
@classmethod
1395+
def caller(cls) -> None:
1396+
cls.bar(1)
1397+
|}
1398+
~define_name:"test.Foo.caller"
1399+
~expected:
1400+
[
1401+
( "23:4-23:14",
1402+
CallGraph.Callees
1403+
(CallGraph.RegularTargets
1404+
{
1405+
CallGraph.implicit_self = true;
1406+
collapse_tito = true;
1407+
targets = [`Method { Callable.class_name = "test.Foo"; method_name = "bar" }];
1408+
}) );
1409+
];
13721410
(* Decorators with type errors. *)
13731411
assert_call_graph_of_define
13741412
~source:

0 commit comments

Comments
 (0)