jaclang 0.4.7__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of jaclang might be problematic. Click here for more details.

Files changed (152) hide show
  1. jaclang/__init__.py +5 -2
  2. jaclang/cli/cli.py +56 -8
  3. jaclang/cli/cmdreg.py +16 -9
  4. jaclang/compiler/__jac_gen__/jac_parser.py +11 -15
  5. jaclang/compiler/absyntree.py +53 -19
  6. jaclang/compiler/codeloc.py +3 -1
  7. jaclang/compiler/{transpiler.py → compile.py} +3 -2
  8. jaclang/compiler/constant.py +4 -0
  9. jaclang/compiler/parser.py +156 -108
  10. jaclang/compiler/passes/ir_pass.py +1 -0
  11. jaclang/compiler/passes/main/__init__.py +2 -1
  12. jaclang/compiler/passes/main/def_impl_match_pass.py +1 -0
  13. jaclang/compiler/passes/main/def_use_pass.py +1 -0
  14. jaclang/compiler/passes/main/import_pass.py +18 -18
  15. jaclang/compiler/passes/main/pyast_gen_pass.py +1228 -853
  16. jaclang/compiler/passes/main/pyast_load_pass.py +3 -1
  17. jaclang/compiler/passes/main/pybc_gen_pass.py +46 -0
  18. jaclang/compiler/passes/main/pyout_pass.py +6 -7
  19. jaclang/compiler/passes/main/schedules.py +5 -9
  20. jaclang/compiler/passes/main/sub_node_tab_pass.py +1 -0
  21. jaclang/compiler/passes/main/sym_tab_build_pass.py +21 -9
  22. jaclang/compiler/passes/main/tests/test_decl_def_match_pass.py +2 -1
  23. jaclang/compiler/passes/main/tests/test_def_use_pass.py +2 -1
  24. jaclang/compiler/passes/main/tests/test_import_pass.py +2 -1
  25. jaclang/compiler/passes/main/tests/test_pyast_build_pass.py +1 -0
  26. jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +15 -38
  27. jaclang/compiler/passes/main/tests/test_pybc_gen_pass.py +25 -0
  28. jaclang/compiler/passes/main/tests/test_sub_node_pass.py +1 -1
  29. jaclang/compiler/passes/main/tests/test_sym_tab_build_pass.py +2 -1
  30. jaclang/compiler/passes/main/tests/test_type_check_pass.py +17 -1
  31. jaclang/compiler/passes/main/type_check_pass.py +9 -6
  32. jaclang/compiler/passes/tool/__init__.py +1 -0
  33. jaclang/compiler/passes/tool/ast_printer_pass.py +1 -0
  34. jaclang/compiler/passes/tool/fuse_comments_pass.py +1 -1
  35. jaclang/compiler/passes/tool/jac_formatter_pass.py +69 -32
  36. jaclang/compiler/passes/tool/schedules.py +1 -0
  37. jaclang/compiler/passes/tool/sym_tab_printer_pass.py +1 -0
  38. jaclang/compiler/passes/tool/tests/test_ast_print_pass.py +2 -1
  39. jaclang/compiler/passes/tool/tests/test_fuse_comments_pass.py +1 -0
  40. jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +4 -3
  41. jaclang/compiler/passes/tool/tests/test_symtab_print_pass.py +2 -1
  42. jaclang/compiler/passes/transform.py +1 -0
  43. jaclang/compiler/passes/utils/mypy_ast_build.py +203 -17
  44. jaclang/compiler/symtable.py +1 -0
  45. jaclang/compiler/tests/test_importer.py +3 -2
  46. jaclang/compiler/tests/test_parser.py +1 -0
  47. jaclang/compiler/tests/test_workspace.py +1 -0
  48. jaclang/compiler/workspace.py +18 -5
  49. jaclang/core/construct.py +9 -32
  50. jaclang/{compiler → core}/importer.py +95 -85
  51. jaclang/core/utils.py +17 -12
  52. jaclang/plugin/__init__.py +1 -0
  53. jaclang/plugin/default.py +145 -43
  54. jaclang/plugin/feature.py +65 -19
  55. jaclang/plugin/spec.py +56 -34
  56. jaclang/plugin/tests/test_features.py +9 -0
  57. jaclang/utils/helpers.py +1 -0
  58. jaclang/utils/lang_tools.py +13 -19
  59. jaclang/utils/tests/test_lang_tools.py +2 -1
  60. jaclang/utils/treeprinter.py +2 -1
  61. jaclang/vendor/lark/common.py +3 -1
  62. jaclang/vendor/lark/lexer.py +6 -12
  63. jaclang/vendor/lark/parsers/lalr_parser.py +1 -0
  64. jaclang/vendor/mypy/applytype.py +2 -1
  65. jaclang/vendor/mypy/binder.py +1 -1
  66. jaclang/vendor/mypy/build.py +7 -9
  67. jaclang/vendor/mypy/checker.py +57 -33
  68. jaclang/vendor/mypy/checkexpr.py +42 -29
  69. jaclang/vendor/mypy/checkmember.py +13 -1
  70. jaclang/vendor/mypy/checkpattern.py +1 -1
  71. jaclang/vendor/mypy/checkstrformat.py +2 -4
  72. jaclang/vendor/mypy/constraints.py +10 -5
  73. jaclang/vendor/mypy/dmypy_server.py +3 -3
  74. jaclang/vendor/mypy/dmypy_util.py +62 -3
  75. jaclang/vendor/mypy/errors.py +1 -1
  76. jaclang/vendor/mypy/evalexpr.py +1 -0
  77. jaclang/vendor/mypy/expandtype.py +29 -29
  78. jaclang/vendor/mypy/fastparse.py +51 -31
  79. jaclang/vendor/mypy/inspections.py +5 -3
  80. jaclang/vendor/mypy/join.py +4 -4
  81. jaclang/vendor/mypy/main.py +6 -6
  82. jaclang/vendor/mypy/message_registry.py +1 -2
  83. jaclang/vendor/mypy/messages.py +31 -23
  84. jaclang/vendor/mypy/metastore.py +1 -2
  85. jaclang/vendor/mypy/modulefinder.py +2 -22
  86. jaclang/vendor/mypy/nodes.py +22 -20
  87. jaclang/vendor/mypy/options.py +4 -0
  88. jaclang/vendor/mypy/parse.py +6 -2
  89. jaclang/vendor/mypy/patterns.py +6 -6
  90. jaclang/vendor/mypy/plugin.py +3 -1
  91. jaclang/vendor/mypy/plugins/attrs.py +52 -10
  92. jaclang/vendor/mypy/plugins/common.py +2 -1
  93. jaclang/vendor/mypy/plugins/enums.py +3 -2
  94. jaclang/vendor/mypy/plugins/functools.py +1 -0
  95. jaclang/vendor/mypy/renaming.py +1 -1
  96. jaclang/vendor/mypy/report.py +15 -15
  97. jaclang/vendor/mypy/semanal.py +22 -13
  98. jaclang/vendor/mypy/semanal_enum.py +1 -1
  99. jaclang/vendor/mypy/semanal_namedtuple.py +1 -2
  100. jaclang/vendor/mypy/semanal_shared.py +3 -6
  101. jaclang/vendor/mypy/semanal_typeddict.py +16 -5
  102. jaclang/vendor/mypy/server/astdiff.py +15 -9
  103. jaclang/vendor/mypy/server/astmerge.py +5 -5
  104. jaclang/vendor/mypy/stats.py +0 -5
  105. jaclang/vendor/mypy/stubdoc.py +1 -1
  106. jaclang/vendor/mypy/stubgen.py +12 -21
  107. jaclang/vendor/mypy/stubgenc.py +16 -8
  108. jaclang/vendor/mypy/stubtest.py +57 -48
  109. jaclang/vendor/mypy/stubutil.py +28 -15
  110. jaclang/vendor/mypy/subtypes.py +4 -4
  111. jaclang/vendor/mypy/test/helpers.py +2 -2
  112. jaclang/vendor/mypy/test/meta/test_parse_data.py +1 -0
  113. jaclang/vendor/mypy/test/meta/test_update_data.py +1 -0
  114. jaclang/vendor/mypy/test/testargs.py +1 -0
  115. jaclang/vendor/mypy/test/testcheck.py +4 -1
  116. jaclang/vendor/mypy/test/testconstraints.py +25 -7
  117. jaclang/vendor/mypy/test/testerrorstream.py +1 -0
  118. jaclang/vendor/mypy/test/testformatter.py +2 -2
  119. jaclang/vendor/mypy/test/testparse.py +6 -4
  120. jaclang/vendor/mypy/test/testpythoneval.py +1 -0
  121. jaclang/vendor/mypy/test/testreports.py +1 -0
  122. jaclang/vendor/mypy/test/teststubgen.py +1 -2
  123. jaclang/vendor/mypy/test/teststubtest.py +98 -4
  124. jaclang/vendor/mypy/test/testtypes.py +1 -1
  125. jaclang/vendor/mypy/test/testutil.py +22 -0
  126. jaclang/vendor/mypy/typeanal.py +302 -158
  127. jaclang/vendor/mypy/typeops.py +22 -13
  128. jaclang/vendor/mypy/types.py +33 -34
  129. jaclang/vendor/mypy/typestate.py +2 -2
  130. jaclang/vendor/mypy/util.py +7 -6
  131. jaclang/vendor/mypy/version.py +1 -1
  132. jaclang/vendor/mypyc/analysis/ircheck.py +1 -0
  133. jaclang/vendor/mypyc/codegen/emitfunc.py +5 -3
  134. jaclang/vendor/mypyc/codegen/emitmodule.py +12 -12
  135. jaclang/vendor/mypyc/codegen/emitwrapper.py +2 -2
  136. jaclang/vendor/mypyc/ir/class_ir.py +10 -6
  137. jaclang/vendor/mypyc/irbuild/builder.py +3 -4
  138. jaclang/vendor/mypyc/irbuild/function.py +5 -3
  139. jaclang/vendor/mypyc/irbuild/nonlocalcontrol.py +1 -2
  140. jaclang/vendor/mypyc/irbuild/prepare.py +6 -6
  141. jaclang/vendor/mypyc/primitives/registry.py +15 -5
  142. jaclang/vendor/mypyc/test/test_run.py +1 -2
  143. jaclang/vendor/mypyc/transform/uninit.py +3 -3
  144. jaclang/vendor/pluggy/_callers.py +1 -0
  145. jaclang/vendor/pluggy/_hooks.py +6 -10
  146. jaclang/vendor/pluggy/_result.py +1 -0
  147. jaclang/vendor/pluggy/_tracing.py +1 -0
  148. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/METADATA +1 -1
  149. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/RECORD +152 -150
  150. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/WHEEL +0 -0
  151. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/entry_points.txt +0 -0
  152. {jaclang-0.4.7.dist-info → jaclang-0.5.0.dist-info}/top_level.txt +0 -0
@@ -599,15 +599,15 @@ def _remove_redundant_union_items(items: list[Type], keep_erased: bool) -> list[
599
599
  return items
600
600
 
601
601
 
602
- def _get_type_special_method_bool_ret_type(t: Type) -> Type | None:
602
+ def _get_type_method_ret_type(t: Type, *, name: str) -> Type | None:
603
603
  t = get_proper_type(t)
604
604
 
605
605
  if isinstance(t, Instance):
606
- bool_method = t.type.get("__bool__")
607
- if bool_method:
608
- callee = get_proper_type(bool_method.type)
609
- if isinstance(callee, CallableType):
610
- return callee.ret_type
606
+ sym = t.type.get(name)
607
+ if sym:
608
+ sym_type = get_proper_type(sym.type)
609
+ if isinstance(sym_type, CallableType):
610
+ return sym_type.ret_type
611
611
 
612
612
  return None
613
613
 
@@ -630,7 +630,9 @@ def true_only(t: Type) -> ProperType:
630
630
  can_be_true_items = [item for item in new_items if item.can_be_true]
631
631
  return make_simplified_union(can_be_true_items, line=t.line, column=t.column)
632
632
  else:
633
- ret_type = _get_type_special_method_bool_ret_type(t)
633
+ ret_type = _get_type_method_ret_type(
634
+ t, name="__bool__"
635
+ ) or _get_type_method_ret_type(t, name="__len__")
634
636
 
635
637
  if ret_type and not ret_type.can_be_true:
636
638
  return UninhabitedType(line=t.line, column=t.column)
@@ -663,9 +665,14 @@ def false_only(t: Type) -> ProperType:
663
665
  can_be_false_items = [item for item in new_items if item.can_be_false]
664
666
  return make_simplified_union(can_be_false_items, line=t.line, column=t.column)
665
667
  else:
666
- ret_type = _get_type_special_method_bool_ret_type(t)
667
-
668
- if ret_type and not ret_type.can_be_false:
668
+ ret_type = _get_type_method_ret_type(
669
+ t, name="__bool__"
670
+ ) or _get_type_method_ret_type(t, name="__len__")
671
+
672
+ if ret_type:
673
+ if not ret_type.can_be_false:
674
+ return UninhabitedType(line=t.line)
675
+ elif isinstance(t, Instance) and t.type.is_final:
669
676
  return UninhabitedType(line=t.line)
670
677
 
671
678
  new_t = copy_type(t)
@@ -945,9 +952,11 @@ def try_contracting_literals_in_union(types: Sequence[Type]) -> list[ProperType]
945
952
  if typ.fallback.type.is_enum or isinstance(typ.value, bool):
946
953
  if fullname not in sum_types:
947
954
  sum_types[fullname] = (
948
- set(typ.fallback.get_enum_values())
949
- if typ.fallback.type.is_enum
950
- else {True, False},
955
+ (
956
+ set(typ.fallback.get_enum_values())
957
+ if typ.fallback.type.is_enum
958
+ else {True, False}
959
+ ),
951
960
  [],
952
961
  )
953
962
  literals, indexes = sum_types[fullname]
@@ -56,7 +56,7 @@ JsonDict: _TypeAlias = Dict[str, Any]
56
56
  # 1. types.LiteralType's serialize and deserialize methods: this method
57
57
  # needs to make sure it can convert the below types into JSON and back.
58
58
  #
59
- # 2. types.LiteralType's 'alue_repr` method: this method is ultimately used
59
+ # 2. types.LiteralType's 'value_repr` method: this method is ultimately used
60
60
  # by TypeStrVisitor's visit_literal_type to generate a reasonable
61
61
  # repr-able output.
62
62
  #
@@ -455,7 +455,7 @@ class TypeGuardedType(Type):
455
455
 
456
456
  __slots__ = ("type_guard",)
457
457
 
458
- def __init__(self, type_guard: Type):
458
+ def __init__(self, type_guard: Type) -> None:
459
459
  super().__init__(line=type_guard.line, column=type_guard.column)
460
460
  self.type_guard = type_guard
461
461
 
@@ -1200,9 +1200,9 @@ class AnyType(ProperType):
1200
1200
  return {
1201
1201
  ".class": "AnyType",
1202
1202
  "type_of_any": self.type_of_any,
1203
- "source_any": self.source_any.serialize()
1204
- if self.source_any is not None
1205
- else None,
1203
+ "source_any": (
1204
+ self.source_any.serialize() if self.source_any is not None else None
1205
+ ),
1206
1206
  "missing_import_name": self.missing_import_name,
1207
1207
  }
1208
1208
 
@@ -1541,9 +1541,11 @@ class Instance(ProperType):
1541
1541
  args if args is not _dummy else self.args,
1542
1542
  self.line,
1543
1543
  self.column,
1544
- last_known_value=last_known_value
1545
- if last_known_value is not _dummy
1546
- else self.last_known_value,
1544
+ last_known_value=(
1545
+ last_known_value
1546
+ if last_known_value is not _dummy
1547
+ else self.last_known_value
1548
+ ),
1547
1549
  )
1548
1550
  # We intentionally don't copy the extra_attrs here, so they will be erased.
1549
1551
  new.can_be_true = self.can_be_true
@@ -1970,13 +1972,13 @@ class CallableType(FunctionLike):
1970
1972
  ),
1971
1973
  implicit=implicit if implicit is not _dummy else self.implicit,
1972
1974
  special_sig=special_sig if special_sig is not _dummy else self.special_sig,
1973
- from_type_type=from_type_type
1974
- if from_type_type is not _dummy
1975
- else self.from_type_type,
1975
+ from_type_type=(
1976
+ from_type_type if from_type_type is not _dummy else self.from_type_type
1977
+ ),
1976
1978
  bound_args=bound_args if bound_args is not _dummy else self.bound_args,
1977
- def_extras=def_extras
1978
- if def_extras is not _dummy
1979
- else dict(self.def_extras),
1979
+ def_extras=(
1980
+ def_extras if def_extras is not _dummy else dict(self.def_extras)
1981
+ ),
1980
1982
  type_guard=type_guard if type_guard is not _dummy else self.type_guard,
1981
1983
  from_concatenate=(
1982
1984
  from_concatenate
@@ -1988,9 +1990,9 @@ class CallableType(FunctionLike):
1988
1990
  if imprecise_arg_kinds is not _dummy
1989
1991
  else self.imprecise_arg_kinds
1990
1992
  ),
1991
- unpack_kwargs=unpack_kwargs
1992
- if unpack_kwargs is not _dummy
1993
- else self.unpack_kwargs,
1993
+ unpack_kwargs=(
1994
+ unpack_kwargs if unpack_kwargs is not _dummy else self.unpack_kwargs
1995
+ ),
1994
1996
  )
1995
1997
  # Optimization: Only NewTypes are supported as subtypes since
1996
1998
  # the class is effectively final, so we can use a cast safely.
@@ -2168,9 +2170,11 @@ class CallableType(FunctionLike):
2168
2170
  last_type = get_proper_type(self.arg_types[-1])
2169
2171
  assert isinstance(last_type, TypedDictType)
2170
2172
  extra_kinds = [
2171
- ArgKind.ARG_NAMED
2172
- if name in last_type.required_keys
2173
- else ArgKind.ARG_NAMED_OPT
2173
+ (
2174
+ ArgKind.ARG_NAMED
2175
+ if name in last_type.required_keys
2176
+ else ArgKind.ARG_NAMED_OPT
2177
+ )
2174
2178
  for name in last_type.items
2175
2179
  ]
2176
2180
  new_arg_kinds = self.arg_kinds[:-1] + extra_kinds
@@ -2304,9 +2308,9 @@ class CallableType(FunctionLike):
2304
2308
  (None if t is None else t.serialize()) for t in self.bound_args
2305
2309
  ],
2306
2310
  "def_extras": dict(self.def_extras),
2307
- "type_guard": self.type_guard.serialize()
2308
- if self.type_guard is not None
2309
- else None,
2311
+ "type_guard": (
2312
+ self.type_guard.serialize() if self.type_guard is not None else None
2313
+ ),
2310
2314
  "from_concatenate": self.from_concatenate,
2311
2315
  "imprecise_arg_kinds": self.imprecise_arg_kinds,
2312
2316
  "unpack_kwargs": self.unpack_kwargs,
@@ -2943,13 +2947,11 @@ class UnionType(ProperType):
2943
2947
  @staticmethod
2944
2948
  def make_union(
2945
2949
  items: Sequence[ProperType], line: int = -1, column: int = -1
2946
- ) -> ProperType:
2947
- ...
2950
+ ) -> ProperType: ...
2948
2951
 
2949
2952
  @overload
2950
2953
  @staticmethod
2951
- def make_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type:
2952
- ...
2954
+ def make_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type: ...
2953
2955
 
2954
2956
  @staticmethod
2955
2957
  def make_union(items: Sequence[Type], line: int = -1, column: int = -1) -> Type:
@@ -3167,13 +3169,11 @@ class PlaceholderType(ProperType):
3167
3169
 
3168
3170
 
3169
3171
  @overload
3170
- def get_proper_type(typ: None) -> None:
3171
- ...
3172
+ def get_proper_type(typ: None) -> None: ...
3172
3173
 
3173
3174
 
3174
3175
  @overload
3175
- def get_proper_type(typ: Type) -> ProperType:
3176
- ...
3176
+ def get_proper_type(typ: Type) -> ProperType: ...
3177
3177
 
3178
3178
 
3179
3179
  def get_proper_type(typ: Type | None) -> ProperType | None:
@@ -3203,8 +3203,7 @@ def get_proper_types(types: list[Type] | tuple[Type, ...]) -> list[ProperType]:
3203
3203
  @overload
3204
3204
  def get_proper_types(
3205
3205
  types: list[Type | None] | tuple[Type | None, ...]
3206
- ) -> list[ProperType | None]:
3207
- ...
3206
+ ) -> list[ProperType | None]: ...
3208
3207
 
3209
3208
 
3210
3209
  def get_proper_types(
@@ -3226,7 +3225,7 @@ def get_proper_types(
3226
3225
  # to make it easier to gradually get modules working with mypyc.
3227
3226
  # Import them here, after the types are defined.
3228
3227
  # This is intended as a re-export also.
3229
- from mypy.type_visitor import ( # noqa: F811
3228
+ from mypy.type_visitor import (
3230
3229
  ALL_STRATEGY as ALL_STRATEGY,
3231
3230
  ANY_STRATEGY as ANY_STRATEGY,
3232
3231
  BoolTypeQuery as BoolTypeQuery,
@@ -194,7 +194,7 @@ class TypeState:
194
194
  # These are unlikely to match, due to the large space of
195
195
  # possible values. Avoid uselessly increasing cache sizes.
196
196
  return
197
- cache = self._subtype_caches.setdefault(right.type, dict())
197
+ cache = self._subtype_caches.setdefault(right.type, {})
198
198
  cache.setdefault(kind, set()).add((left, right))
199
199
 
200
200
  def record_negative_subtype_cache_entry(
@@ -206,7 +206,7 @@ class TypeState:
206
206
  return
207
207
  if len(self._negative_subtype_caches) > MAX_NEGATIVE_CACHE_TYPES:
208
208
  self._negative_subtype_caches.clear()
209
- cache = self._negative_subtype_caches.setdefault(right.type, dict())
209
+ cache = self._negative_subtype_caches.setdefault(right.type, {})
210
210
  subcache = cache.setdefault(kind, set())
211
211
  if len(subcache) > MAX_NEGATIVE_CACHE_ENTRIES:
212
212
  subcache.clear()
@@ -270,6 +270,8 @@ def _generate_junit_contents(
270
270
  version: str,
271
271
  platform: str,
272
272
  ) -> str:
273
+ from xml.sax.saxutils import escape
274
+
273
275
  if serious:
274
276
  failures = 0
275
277
  errors = len(messages_by_file)
@@ -293,7 +295,7 @@ def _generate_junit_contents(
293
295
  for filename, messages in messages_by_file.items():
294
296
  if filename is not None:
295
297
  xml += JUNIT_TESTCASE_FAIL_TEMPLATE.format(
296
- text="\n".join(messages),
298
+ text=escape("\n".join(messages)),
297
299
  filename=filename,
298
300
  time=dt,
299
301
  name="mypy-py{ver}-{platform} {filename}".format(
@@ -302,7 +304,7 @@ def _generate_junit_contents(
302
304
  )
303
305
  else:
304
306
  xml += JUNIT_TESTCASE_FAIL_TEMPLATE.format(
305
- text="\n".join(messages),
307
+ text=escape("\n".join(messages)),
306
308
  filename="mypy",
307
309
  time=dt,
308
310
  name="mypy-py{ver}-{platform}".format(
@@ -325,10 +327,9 @@ def write_junit_xml(
325
327
  ) -> None:
326
328
  xml = _generate_junit_contents(dt, serious, messages_by_file, version, platform)
327
329
 
328
- # checks for a directory structure in path and creates folders if needed
330
+ # creates folders if needed
329
331
  xml_dirs = os.path.dirname(os.path.abspath(path))
330
- if not os.path.isdir(xml_dirs):
331
- os.makedirs(xml_dirs)
332
+ os.makedirs(xml_dirs, exist_ok=True)
332
333
 
333
334
  with open(path, "wb") as f:
334
335
  f.write(xml.encode("utf-8"))
@@ -464,7 +465,7 @@ def get_unique_redefinition_name(name: str, existing: Container[str]) -> str:
464
465
  def check_python_version(program: str) -> None:
465
466
  """Report issues with the Python used to run mypy, dmypy, or stubgen"""
466
467
  # Check for known bad Python versions.
467
- if sys.version_info[:2] < (3, 8):
468
+ if sys.version_info[:2] < (3, 8): # noqa: UP036
468
469
  sys.exit(
469
470
  "Running {name} with Python 3.7 or lower is not supported; "
470
471
  "please upgrade to 3.8 or newer".format(name=program)
@@ -8,7 +8,7 @@ from mypy import git
8
8
  # - Release versions have the form "1.2.3".
9
9
  # - Dev versions have the form "1.2.3+dev" (PLUS sign to conform to PEP 440).
10
10
  # - Before 1.0 we had the form "0.NNN".
11
- __version__ = "1.8.0+dev"
11
+ __version__ = "1.9.0+dev"
12
12
  base_version = __version__
13
13
 
14
14
  mypy_dir = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
@@ -1,4 +1,5 @@
1
1
  """Utilities for checking that internal ir is valid and consistent."""
2
+
2
3
  from __future__ import annotations
3
4
 
4
5
  from mypyc.ir.func_ir import FUNC_STATICMETHOD, FuncIR
@@ -559,9 +559,11 @@ class FunctionEmitterVisitor(OpVisitor[None]):
559
559
  obj_args = (
560
560
  []
561
561
  if method.decl.kind == FUNC_STATICMETHOD
562
- else [f"(PyObject *)Py_TYPE({obj})"]
563
- if method.decl.kind == FUNC_CLASSMETHOD
564
- else [obj]
562
+ else (
563
+ [f"(PyObject *)Py_TYPE({obj})"]
564
+ if method.decl.kind == FUNC_CLASSMETHOD
565
+ else [obj]
566
+ )
565
567
  )
566
568
  args = ", ".join(obj_args + [self.reg(arg) for arg in op.args])
567
569
  mtype = native_function_type(method, self.emitter)
@@ -461,21 +461,21 @@ def compile_modules_to_c(
461
461
 
462
462
 
463
463
  def generate_function_declaration(fn: FuncIR, emitter: Emitter) -> None:
464
- emitter.context.declarations[
465
- emitter.native_function_name(fn.decl)
466
- ] = HeaderDeclaration(
467
- f"{native_function_header(fn.decl, emitter)};", needs_export=True
464
+ emitter.context.declarations[emitter.native_function_name(fn.decl)] = (
465
+ HeaderDeclaration(
466
+ f"{native_function_header(fn.decl, emitter)};", needs_export=True
467
+ )
468
468
  )
469
469
  if fn.name != TOP_LEVEL_NAME:
470
470
  if is_fastcall_supported(fn, emitter.capi_version):
471
- emitter.context.declarations[
472
- PREFIX + fn.cname(emitter.names)
473
- ] = HeaderDeclaration(f"{wrapper_function_header(fn, emitter.names)};")
471
+ emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = (
472
+ HeaderDeclaration(f"{wrapper_function_header(fn, emitter.names)};")
473
+ )
474
474
  else:
475
- emitter.context.declarations[
476
- PREFIX + fn.cname(emitter.names)
477
- ] = HeaderDeclaration(
478
- f"{legacy_wrapper_function_header(fn, emitter.names)};"
475
+ emitter.context.declarations[PREFIX + fn.cname(emitter.names)] = (
476
+ HeaderDeclaration(
477
+ f"{legacy_wrapper_function_header(fn, emitter.names)};"
478
+ )
479
479
  )
480
480
 
481
481
 
@@ -1059,7 +1059,7 @@ class GroupGenerator:
1059
1059
  result.append(decl.declaration)
1060
1060
  decl.mark = True
1061
1061
 
1062
- for name, marked_declaration in marked_declarations.items():
1062
+ for name in marked_declarations:
1063
1063
  _toposort_visit(name)
1064
1064
 
1065
1065
  return result
@@ -165,7 +165,7 @@ def generate_wrapper_function(
165
165
  real_args = list(fn.args)
166
166
  if fn.sig.num_bitmap_args:
167
167
  real_args = real_args[: -fn.sig.num_bitmap_args]
168
- if fn.class_name and not fn.decl.kind == FUNC_STATICMETHOD:
168
+ if fn.class_name and fn.decl.kind != FUNC_STATICMETHOD:
169
169
  arg = real_args.pop(0)
170
170
  emitter.emit_line(f"PyObject *obj_{arg.name} = self;")
171
171
 
@@ -264,7 +264,7 @@ def generate_legacy_wrapper_function(
264
264
  real_args = list(fn.args)
265
265
  if fn.sig.num_bitmap_args:
266
266
  real_args = real_args[: -fn.sig.num_bitmap_args]
267
- if fn.class_name and not fn.decl.kind == FUNC_STATICMETHOD:
267
+ if fn.class_name and fn.decl.kind != FUNC_STATICMETHOD:
268
268
  arg = real_args.pop(0)
269
269
  emitter.emit_line(f"PyObject *obj_{arg.name} = self;")
270
270
 
@@ -388,9 +388,11 @@ class ClassIR:
388
388
  "traits": [cir.fullname for cir in self.traits],
389
389
  "mro": [cir.fullname for cir in self.mro],
390
390
  "base_mro": [cir.fullname for cir in self.base_mro],
391
- "children": [cir.fullname for cir in self.children]
392
- if self.children is not None
393
- else None,
391
+ "children": (
392
+ [cir.fullname for cir in self.children]
393
+ if self.children is not None
394
+ else None
395
+ ),
394
396
  "deletable": self.deletable,
395
397
  "attrs_with_defaults": sorted(self.attrs_with_defaults),
396
398
  "_always_initialized_attrs": sorted(self._always_initialized_attrs),
@@ -418,9 +420,11 @@ class ClassIR:
418
420
  ir.ctor = FuncDecl.deserialize(data["ctor"], ctx)
419
421
  ir.attributes = {k: deserialize_type(t, ctx) for k, t in data["attributes"]}
420
422
  ir.method_decls = {
421
- k: ctx.functions[v].decl
422
- if isinstance(v, str)
423
- else FuncDecl.deserialize(v, ctx)
423
+ k: (
424
+ ctx.functions[v].decl
425
+ if isinstance(v, str)
426
+ else FuncDecl.deserialize(v, ctx)
427
+ )
424
428
  for k, v in data["method_decls"]
425
429
  }
426
430
  ir.methods = {k: ctx.functions[v] for k, v in data["methods"]}
@@ -10,6 +10,7 @@ AST node type to code that actually does the bulk of the work. For
10
10
  example, expressions are transformed in mypyc.irbuild.expression and
11
11
  functions are transformed in mypyc.irbuild.function.
12
12
  """
13
+
13
14
  from __future__ import annotations
14
15
 
15
16
  from contextlib import contextmanager
@@ -241,12 +242,10 @@ class IRBuilder:
241
242
  self.builder.set_module(module_name, module_path)
242
243
 
243
244
  @overload
244
- def accept(self, node: Expression, *, can_borrow: bool = False) -> Value:
245
- ...
245
+ def accept(self, node: Expression, *, can_borrow: bool = False) -> Value: ...
246
246
 
247
247
  @overload
248
- def accept(self, node: Statement) -> None:
249
- ...
248
+ def accept(self, node: Statement) -> None: ...
250
249
 
251
250
  def accept(
252
251
  self, node: Statement | Expression, *, can_borrow: bool = False
@@ -655,9 +655,11 @@ def get_args(builder: IRBuilder, rt_args: Sequence[RuntimeArg], line: int) -> Ar
655
655
  for var, type in fake_vars
656
656
  ]
657
657
  arg_names = [
658
- arg.name
659
- if arg.kind.is_named() or (arg.kind.is_optional() and not arg.pos_only)
660
- else None
658
+ (
659
+ arg.name
660
+ if arg.kind.is_named() or (arg.kind.is_optional() and not arg.pos_only)
661
+ else None
662
+ )
661
663
  for arg in rt_args
662
664
  ]
663
665
  arg_kinds = [arg.kind for arg in rt_args]
@@ -125,8 +125,7 @@ class CleanupNonlocalControl(NonlocalControl):
125
125
  self.outer = outer
126
126
 
127
127
  @abstractmethod
128
- def gen_cleanup(self, builder: IRBuilder, line: int) -> None:
129
- ...
128
+ def gen_cleanup(self, builder: IRBuilder, line: int) -> None: ...
130
129
 
131
130
  def gen_break(self, builder: IRBuilder, line: int) -> None:
132
131
  self.gen_cleanup(builder, line)
@@ -156,7 +156,7 @@ def load_type_map(
156
156
  ) -> None:
157
157
  """Populate a Mapper with deserialized IR from a list of modules."""
158
158
  for module in modules:
159
- for name, node in module.names.items():
159
+ for node in module.names.values():
160
160
  if isinstance(node.node, TypeInfo) and is_from_module(node.node, module):
161
161
  ir = deser_ctx.classes[node.node.fullname]
162
162
  mapper.type_to_ir[node.node] = ir
@@ -170,7 +170,7 @@ def load_type_map(
170
170
 
171
171
  def get_module_func_defs(module: MypyFile) -> Iterable[FuncDef]:
172
172
  """Collect all of the (non-method) functions declared in a module."""
173
- for name, node in module.names.items():
173
+ for node in module.names.values():
174
174
  # We need to filter out functions that are imported or
175
175
  # aliases. The best way to do this seems to be by
176
176
  # checking that the fullname matches.
@@ -513,7 +513,7 @@ def prepare_non_ext_class_def(
513
513
  ir = mapper.type_to_ir[cdef.info]
514
514
  info = cdef.info
515
515
 
516
- for name, node in info.names.items():
516
+ for node in info.names.values():
517
517
  if isinstance(node.node, (FuncDef, Decorator)):
518
518
  prepare_method_def(ir, module_name, cdef, mapper, node.node)
519
519
  elif isinstance(node.node, OverloadedFuncDef):
@@ -569,9 +569,9 @@ class SingledispatchVisitor(TraverserVisitor):
569
569
  super().__init__()
570
570
 
571
571
  # Map of main singledispatch function to list of registered implementations
572
- self.singledispatch_impls: defaultdict[
573
- FuncDef, list[RegisterImplInfo]
574
- ] = defaultdict(list)
572
+ self.singledispatch_impls: defaultdict[FuncDef, list[RegisterImplInfo]] = (
573
+ defaultdict(list)
574
+ )
575
575
 
576
576
  # Map of decorated function to the indices of any decorators to remove
577
577
  self.decorators_to_remove: dict[FuncDef, list[int]] = {}
@@ -93,7 +93,7 @@ def method_op(
93
93
  var_arg_type: RType | None = None,
94
94
  truncated_type: RType | None = None,
95
95
  ordering: list[int] | None = None,
96
- extra_int_constants: list[tuple[int, RType]] = [],
96
+ extra_int_constants: list[tuple[int, RType]] | None = None,
97
97
  steals: StealsDescription = False,
98
98
  is_borrowed: bool = False,
99
99
  priority: int = 1,
@@ -122,6 +122,8 @@ def method_op(
122
122
  is_borrowed: if True, returned value is borrowed (no need to decrease refcount)
123
123
  priority: if multiple ops match, the one with the highest priority is picked
124
124
  """
125
+ if extra_int_constants is None:
126
+ extra_int_constants = []
125
127
  ops = method_call_ops.setdefault(name, [])
126
128
  desc = CFunctionDescription(
127
129
  name,
@@ -150,7 +152,7 @@ def function_op(
150
152
  var_arg_type: RType | None = None,
151
153
  truncated_type: RType | None = None,
152
154
  ordering: list[int] | None = None,
153
- extra_int_constants: list[tuple[int, RType]] = [],
155
+ extra_int_constants: list[tuple[int, RType]] | None = None,
154
156
  steals: StealsDescription = False,
155
157
  is_borrowed: bool = False,
156
158
  priority: int = 1,
@@ -165,6 +167,8 @@ def function_op(
165
167
  name: full name of the function
166
168
  arg_types: positional argument types for which this applies
167
169
  """
170
+ if extra_int_constants is None:
171
+ extra_int_constants = []
168
172
  ops = function_ops.setdefault(name, [])
169
173
  desc = CFunctionDescription(
170
174
  name,
@@ -193,7 +197,7 @@ def binary_op(
193
197
  var_arg_type: RType | None = None,
194
198
  truncated_type: RType | None = None,
195
199
  ordering: list[int] | None = None,
196
- extra_int_constants: list[tuple[int, RType]] = [],
200
+ extra_int_constants: list[tuple[int, RType]] | None = None,
197
201
  steals: StealsDescription = False,
198
202
  is_borrowed: bool = False,
199
203
  priority: int = 1,
@@ -205,6 +209,8 @@ def binary_op(
205
209
  Most arguments are similar to method_op(), but exactly two argument types
206
210
  are expected.
207
211
  """
212
+ if extra_int_constants is None:
213
+ extra_int_constants = []
208
214
  ops = binary_ops.setdefault(name, [])
209
215
  desc = CFunctionDescription(
210
216
  name,
@@ -232,7 +238,7 @@ def custom_op(
232
238
  var_arg_type: RType | None = None,
233
239
  truncated_type: RType | None = None,
234
240
  ordering: list[int] | None = None,
235
- extra_int_constants: list[tuple[int, RType]] = [],
241
+ extra_int_constants: list[tuple[int, RType]] | None = None,
236
242
  steals: StealsDescription = False,
237
243
  is_borrowed: bool = False,
238
244
  ) -> CFunctionDescription:
@@ -240,6 +246,8 @@ def custom_op(
240
246
 
241
247
  Most arguments are similar to method_op().
242
248
  """
249
+ if extra_int_constants is None:
250
+ extra_int_constants = []
243
251
  return CFunctionDescription(
244
252
  "<custom>",
245
253
  arg_types,
@@ -264,7 +272,7 @@ def unary_op(
264
272
  error_kind: int,
265
273
  truncated_type: RType | None = None,
266
274
  ordering: list[int] | None = None,
267
- extra_int_constants: list[tuple[int, RType]] = [],
275
+ extra_int_constants: list[tuple[int, RType]] | None = None,
268
276
  steals: StealsDescription = False,
269
277
  is_borrowed: bool = False,
270
278
  priority: int = 1,
@@ -276,6 +284,8 @@ def unary_op(
276
284
  Most arguments are similar to method_op(), but exactly one argument type
277
285
  is expected.
278
286
  """
287
+ if extra_int_constants is None:
288
+ extra_int_constants = []
279
289
  ops = unary_ops.setdefault(name, [])
280
290
  desc = CFunctionDescription(
281
291
  name,
@@ -15,7 +15,7 @@ from typing import Any, Iterator
15
15
 
16
16
  from mypy import build
17
17
  from mypy.errors import CompileError
18
- from mypy.options import TYPE_VAR_TUPLE, UNPACK, Options
18
+ from mypy.options import Options
19
19
  from mypy.test.config import test_temp_dir
20
20
  from mypy.test.data import DataDrivenTestCase
21
21
  from mypy.test.helpers import assert_module_equivalence, perform_file_operations
@@ -198,7 +198,6 @@ class TestRun(MypycDataSuite):
198
198
  options.preserve_asts = True
199
199
  options.allow_empty_bodies = True
200
200
  options.incremental = self.separate
201
- options.enable_incomplete_feature = [TYPE_VAR_TUPLE, UNPACK]
202
201
 
203
202
  # Avoid checking modules/packages named 'unchecked', to provide a way
204
203
  # to test interacting with code we don't have types for.
@@ -75,9 +75,9 @@ def split_blocks_at_uninits(
75
75
  and not isinstance(op, LoadAddress)
76
76
  ):
77
77
  new_block, error_block = BasicBlock(), BasicBlock()
78
- new_block.error_handler = (
79
- error_block.error_handler
80
- ) = cur_block.error_handler
78
+ new_block.error_handler = error_block.error_handler = (
79
+ cur_block.error_handler
80
+ )
81
81
  new_blocks += [error_block, new_block]
82
82
 
83
83
  if src not in init_registers_set:
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Call loop machinery
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  from typing import cast