Skip to content

Commit 0852005

Browse files
gbleaneyfacebook-github-bot
authored andcommitted
Move subclass grabbing code into a shared location
Summary: This just moves `all_subclasses` into the more appropriate `subclass_generator` file, and renames it `get_all_subclasses_from_environment` to disambiguate from the pyre related functions. This is being done to support use of this function in IG Reviewed By: dkgi Differential Revision: D30134858 fbshipit-source-id: 405523b599fc1c583859f686c1ab840a384fa42b
1 parent 47faf5f commit 0852005

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

tools/generate_taint_models/constructor_generator.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
from importlib import import_module
1010
from typing import Callable, Iterable, List, Optional, Type, TypeVar
1111

12+
from .subclass_generator import get_all_subclasses_from_environment as all_subclasses
1213

1314
LOG: logging.Logger = logging.getLogger(__name__)
1415
T = TypeVar("T")
1516

1617

17-
def all_subclasses(parent_class: Type[T]) -> Iterable[Type[T]]:
18-
return set(parent_class.__subclasses__()).union(
19-
[s for c in parent_class.__subclasses__() for s in all_subclasses(c)]
20-
)
21-
22-
2318
def gather_all_constructors_in_hierarchy(
2419
classes_to_taint: List[str],
2520
filter_classes_by: Optional[Callable[[Type[T]], bool]] = None,

tools/generate_taint_models/subclass_generator.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# pyre-strict
77

88
import logging
9-
from typing import Dict, Iterable, List, Optional, Set
9+
from typing import TypeVar, Type, Dict, Iterable, List, Optional, Set
1010

1111
from ...api import query
1212
from ...api.connection import PyreConnection
@@ -58,3 +58,16 @@ def get_all_subclass_defines_from_pyre(
5858
}
5959
else:
6060
return None
61+
62+
63+
T = TypeVar("T")
64+
65+
66+
def get_all_subclasses_from_environment(parent_class: Type[T]) -> Iterable[Type[T]]:
67+
return set(parent_class.__subclasses__()).union(
68+
[
69+
grandchild
70+
for child in parent_class.__subclasses__()
71+
for grandchild in get_all_subclasses_from_environment(child)
72+
]
73+
)

0 commit comments

Comments
 (0)