Skip to content

Commit 5a64c78

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3521896 commit 5a64c78

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

misc/analyze_typeform_stats.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def analyze_stats(output: str) -> None:
3737
"""Parse mypy stats output and calculate TypeForm parsing efficiency."""
3838

3939
# Extract the three counters
40-
total_match = re.search(r'type_expression_parse_count:\s*(\d+)', output)
41-
success_match = re.search(r'type_expression_full_parse_success_count:\s*(\d+)', output)
42-
failure_match = re.search(r'type_expression_full_parse_failure_count:\s*(\d+)', output)
40+
total_match = re.search(r"type_expression_parse_count:\s*(\d+)", output)
41+
success_match = re.search(r"type_expression_full_parse_success_count:\s*(\d+)", output)
42+
failure_match = re.search(r"type_expression_full_parse_failure_count:\s*(\d+)", output)
4343

4444
if not (total_match and success_match and failure_match):
4545
print("Error: Could not find all required counters in output")
@@ -51,23 +51,25 @@ def analyze_stats(output: str) -> None:
5151

5252
full_parses = successes + failures
5353

54-
print(f"TypeForm Expression Parsing Statistics:")
55-
print(f"="*50)
54+
print("TypeForm Expression Parsing Statistics:")
55+
print("=" * 50)
5656
print(f"Total calls to SA.try_parse_as_type_expression: {total:,}")
5757
print(f"Quick rejections (no full parse): {total - full_parses:,}")
5858
print(f"Full parses attempted: {full_parses:,}")
5959
print(f" - Successful: {successes:,}")
6060
print(f" - Failed: {failures:,}")
6161
if total > 0:
6262
print()
63-
print(f"Efficiency Metrics:")
63+
print("Efficiency Metrics:")
6464
print(f" - Quick rejection rate: {((total - full_parses) / total * 100):.1f}%")
6565
print(f" - Full parse rate: {(full_parses / total * 100):.1f}%")
6666
print(f" - Full parse success rate: {(successes / full_parses * 100):.1f}%")
6767
print(f" - Overall success rate: {(successes / total * 100):.1f}%")
6868
print()
69-
print(f"Performance Implications:")
70-
print(f" - Expensive failed full parses: {failures:,} ({(failures / total * 100):.1f}% of all calls)")
69+
print("Performance Implications:")
70+
print(
71+
f" - Expensive failed full parses: {failures:,} ({(failures / total * 100):.1f}% of all calls)"
72+
)
7173

7274

7375
if __name__ == "__main__":
@@ -80,7 +82,9 @@ def analyze_stats(output: str) -> None:
8082
else:
8183
print("Usage: python3 analyze_typeform_stats.py [mypy_output_with_stats]")
8284
print("Examples:")
83-
print(" python3 -m mypy --dump-build-stats file.py 2>&1 | python3 analyze_typeform_stats.py")
85+
print(
86+
" python3 -m mypy --dump-build-stats file.py 2>&1 | python3 analyze_typeform_stats.py"
87+
)
8488
print(" python3 analyze_typeform_stats.py 'output_string'")
8589
sys.exit(1)
8690

mypy/checkexpr.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6083,10 +6083,12 @@ def accept(
60836083
) # r-value type, when interpreted as a type expression
60846084
elif (
60856085
isinstance(p_type_context, UnionType)
6086-
and any([
6087-
isinstance(item, TypeType) and item.is_type_form
6088-
for item in p_type_context.items
6089-
])
6086+
and any(
6087+
[
6088+
isinstance(item, TypeType) and item.is_type_form
6089+
for item in p_type_context.items
6090+
]
6091+
)
60906092
and (node_as_type := self.try_parse_as_type_expression(node)) is not None
60916093
):
60926094
typ1 = TypeType.make_normalized(

mypy/errors.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323

2424
# Show error codes for some note-level messages (these usually appear alone
2525
# and not as a comment for a previous error-level message).
26-
SHOW_NOTE_CODES: Final = {
27-
codes.ANNOTATION_UNCHECKED,
28-
codes.DEPRECATED,
29-
}
26+
SHOW_NOTE_CODES: Final = {codes.ANNOTATION_UNCHECKED, codes.DEPRECATED}
3027

3128
# Do not add notes with links to error code docs to errors with these codes.
3229
# We can tweak this set as we get more experience about what is helpful and what is not.

mypy/semanal.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
from __future__ import annotations
5252

5353
import re
54-
import warnings
5554
from collections.abc import Collection, Iterable, Iterator
5655
from contextlib import contextmanager
5756
from typing import Any, Callable, Final, TypeVar, cast
@@ -364,7 +363,7 @@
364363
# [^\d\W] = word character that is not a digit
365364
# \w = word character
366365
# \Z = match end of string; does not allow a trailing \n, unlike $
367-
_IDENTIFIER_RE = re.compile(r'^[^\d\W]\w*\Z', re.UNICODE)
366+
_IDENTIFIER_RE = re.compile(r"^[^\d\W]\w*\Z", re.UNICODE)
368367

369368

370369
class SemanticAnalyzer(
@@ -7770,11 +7769,11 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> None:
77707769
else: # does not look like an identifier
77717770
if '"' in str_value or "'" in str_value:
77727771
# Only valid inside a Literal[...] type
7773-
if '[' not in str_value:
7772+
if "[" not in str_value:
77747773
# Cannot be a Literal[...] type
77757774
maybe_type_expr.as_type = None
77767775
return
7777-
elif str_value == '':
7776+
elif str_value == "":
77787777
# Empty string is not a valid type
77797778
maybe_type_expr.as_type = None
77807779
return
@@ -7828,7 +7827,9 @@ def try_parse_as_type_expression(self, maybe_type_expr: Expression) -> None:
78287827
finally:
78297828
self.errors.flushed_files = original_flushed_files # restore
78307829

7831-
print(f'SA.try_parse_as_type_expression: Full parse failure: {maybe_type_expr}, errors={errors!r}')
7830+
print(
7831+
f"SA.try_parse_as_type_expression: Full parse failure: {maybe_type_expr}, errors={errors!r}"
7832+
)
78327833

78337834
# Count full parse attempts for profiling
78347835
if t is not None:

0 commit comments

Comments
 (0)