Skip to content

Commit 5d2a216

Browse files
committed
Address CR; one more missing wrap_context()
1 parent 20fcce2 commit 5d2a216

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

mypy/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,8 @@ def parse_all(self, states: Iterable[State]) -> None:
959959
if self.options.native_parser:
960960
futures = []
961961
parsed_states = set()
962-
available_threads = get_available_threads()
962+
# Use at least --num-threads if specified by user.
963+
available_threads = max(get_available_threads(), self.options.num_workers)
963964
# Overhead from trying to parallelize (small) blocking portion of
964965
# parse_file_inner() results in no visible improvement with more than 8 threads.
965966
with ThreadPoolExecutor(max_workers=min(available_threads, 8)) as executor:

mypy/semanal_main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,10 @@ def calculate_class_properties(graph: Graph, scc: list[str], errors: Errors) ->
525525
assert tree
526526
for _, node, _ in tree.local_definitions():
527527
if isinstance(node.node, TypeInfo):
528-
with state.manager.semantic_analyzer.file_context(tree, state.options, node.node):
528+
with (
529+
state.wrap_context(),
530+
state.manager.semantic_analyzer.file_context(tree, state.options, node.node),
531+
):
529532
calculate_class_abstract_status(node.node, tree.is_stub, errors)
530533
check_protocol_status(node.node, errors)
531534
calculate_class_vars(node.node)

mypy/util.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -992,18 +992,15 @@ def get_available_threads() -> int:
992992
cpu_count = psutil_cpu_count or os_cpu_count
993993
else:
994994
# A conservative fallback in case we cannot determine CPU count in any way.
995-
cpu_count = 2
995+
cpu_count = 4
996996

997997
affinity = None
998998
# Not available on old Python versions on some platforms.
999999
if sys.platform == "linux":
10001000
affinity = os.sched_getaffinity(0)
1001-
if PSUTIL_AVAILABLE:
1002-
try:
1003-
# Currently not supported on macOS.
1004-
affinity = psutil.Process().cpu_affinity()
1005-
except AttributeError:
1006-
pass
1001+
if PSUTIL_AVAILABLE and sys.platform != "darwin":
1002+
# Currently not supported on macOS.
1003+
affinity = psutil.Process().cpu_affinity()
10071004

10081005
assert cpu_count is not None
10091006
if affinity:

0 commit comments

Comments
 (0)