-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathstubtest_wrapper.py
44 lines (29 loc) · 1.01 KB
/
stubtest_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# workaround for https://github.com/python/mypy/issues/14196
import faulthandler
import sys
import typing
import mypy.stubtest
sentinel = object
def noop_generator(*args, **kwargs) -> typing.Iterator[object]:
return
yield # make it a generator as the original is
def maybe_monkey_patch(object_: object, name: str, replacement: object) -> None:
attribute = getattr(object_, name, sentinel)
if attribute is sentinel:
print(f"{name} does not exist on {object_}, skipping monkey patching")
return
setattr(object_, name, replacement)
print(f"{name} on {object_} monkey patched by {replacement}")
return
def main() -> int:
maybe_monkey_patch(
object_=mypy.stubtest,
name="_verify_final",
replacement=noop_generator,
)
# make sure the messages get out since we're working around a segfault here
sys.stdout.flush()
# in case we still get a segfault, try to report it
faulthandler.enable()
return mypy.stubtest.main()
sys.exit(main())