Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 125 additions & 16 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def write(self, data: WriteBuffer) -> None:
write_tag(data, LITERAL_NONE)
else:
self.impl.write(data)
write_flags(data, self, FUNCBASE_FLAGS)
write_flags(data, [self.is_property, self.is_class, self.is_static, self.is_final])
write_str_opt(data, self.deprecated)
write_int_opt(data, self.setter_index)
write_tag(data, END_TAG)
Expand All @@ -779,7 +779,7 @@ def read(cls, data: ReadBuffer) -> OverloadedFuncDef:
# set line for empty overload items, as not set in __init__
if len(res.items) > 0:
res.set_line(res.impl.line)
read_flags(data, res, FUNCBASE_FLAGS)
res.is_property, res.is_class, res.is_static, res.is_final = read_flags(data, num_flags=4)
res.deprecated = read_str_opt(data)
res.setter_index = read_int_opt(data)
# NOTE: res.info will be set in the fixup phase.
Expand Down Expand Up @@ -1067,7 +1067,25 @@ def write(self, data: WriteBuffer) -> None:
write_str(data, self._name)
mypy.types.write_type_opt(data, self.type)
write_str(data, self._fullname)
write_flags(data, self, FUNCDEF_FLAGS)
write_flags(
data,
[
self.is_property,
self.is_class,
self.is_static,
self.is_final,
self.is_overload,
self.is_generator,
self.is_coroutine,
self.is_async_generator,
self.is_awaitable_coroutine,
self.is_decorated,
self.is_conditional,
self.is_trivial_body,
self.is_trivial_self,
self.is_mypy_only,
],
)
write_str_opt_list(data, self.arg_names)
write_int_list(data, [int(ak.value) for ak in self.arg_kinds])
write_int(data, self.abstract_status)
Expand All @@ -1088,7 +1106,22 @@ def read(cls, data: ReadBuffer) -> FuncDef:
typ = mypy.types.read_function_like(data, tag)
ret = FuncDef(name, [], Block([]), typ)
ret._fullname = read_str(data)
read_flags(data, ret, FUNCDEF_FLAGS)
(
ret.is_property,
ret.is_class,
ret.is_static,
ret.is_final,
ret.is_overload,
ret.is_generator,
ret.is_coroutine,
ret.is_async_generator,
ret.is_awaitable_coroutine,
ret.is_decorated,
ret.is_conditional,
ret.is_trivial_body,
ret.is_trivial_self,
ret.is_mypy_only,
) = read_flags(data, num_flags=14)
# NOTE: ret.info is set in the fixup phase.
ret.arg_names = read_str_opt_list(data)
ret.arg_kinds = [ARG_KINDS[ak] for ak in read_int_list(data)]
Expand Down Expand Up @@ -1378,7 +1411,32 @@ def write(self, data: WriteBuffer) -> None:
mypy.types.write_type_opt(data, self.type)
mypy.types.write_type_opt(data, self.setter_type)
write_str(data, self._fullname)
write_flags(data, self, VAR_FLAGS)
write_flags(
data,
[
self.is_self,
self.is_cls,
self.is_initialized_in_class,
self.is_staticmethod,
self.is_classmethod,
self.is_property,
self.is_settable_property,
self.is_suppressed_import,
self.is_classvar,
self.is_abstract_var,
self.is_final,
self.is_index_var,
self.final_unset_in_class,
self.final_set_in_init,
self.explicit_self_type,
self.is_ready,
self.is_inferred,
self.invalid_partial_type,
self.from_module_getattr,
self.has_explicit_value,
self.allow_incompatible_override,
],
)
write_literal(data, self.final_value)
write_tag(data, END_TAG)

Expand All @@ -1393,9 +1451,30 @@ def read(cls, data: ReadBuffer) -> Var:
assert tag == mypy.types.CALLABLE_TYPE
setter_type = mypy.types.CallableType.read(data)
v.setter_type = setter_type
v.is_ready = False # Override True default set in __init__
v._fullname = read_str(data)
read_flags(data, v, VAR_FLAGS)
(
v.is_self,
v.is_cls,
v.is_initialized_in_class,
v.is_staticmethod,
v.is_classmethod,
v.is_property,
v.is_settable_property,
v.is_suppressed_import,
v.is_classvar,
v.is_abstract_var,
v.is_final,
v.is_index_var,
v.final_unset_in_class,
v.final_set_in_init,
v.explicit_self_type,
v.is_ready,
v.is_inferred,
v.invalid_partial_type,
v.from_module_getattr,
v.has_explicit_value,
v.allow_incompatible_override,
) = read_flags(data, num_flags=21)
tag = read_tag(data)
if tag == LITERAL_COMPLEX:
v.final_value = complex(read_float_bare(data), read_float_bare(data))
Expand Down Expand Up @@ -4035,7 +4114,22 @@ def write(self, data: WriteBuffer) -> None:
mypy.types.write_type_opt(data, self.metaclass_type)
mypy.types.write_type_opt(data, self.tuple_type)
mypy.types.write_type_opt(data, self.typeddict_type)
write_flags(data, self, TypeInfo.FLAGS)
write_flags(
data,
[
self.is_abstract,
self.is_enum,
self.fallback_to_any,
self.meta_fallback_to_any,
self.is_named_tuple,
self.is_newtype,
self.is_protocol,
self.runtime_protocol,
self.is_final,
self.is_disjoint_base,
self.is_intersection,
],
)
write_json(data, self.metadata)
if self.slots is None:
write_tag(data, LITERAL_NONE)
Expand Down Expand Up @@ -4095,7 +4189,19 @@ def read(cls, data: ReadBuffer) -> TypeInfo:
if (tag := read_tag(data)) != LITERAL_NONE:
assert tag == mypy.types.TYPED_DICT_TYPE
ti.typeddict_type = mypy.types.TypedDictType.read(data)
read_flags(data, ti, TypeInfo.FLAGS)
(
ti.is_abstract,
ti.is_enum,
ti.fallback_to_any,
ti.meta_fallback_to_any,
ti.is_named_tuple,
ti.is_newtype,
ti.is_protocol,
ti.runtime_protocol,
ti.is_final,
ti.is_disjoint_base,
ti.is_intersection,
) = read_flags(data, num_flags=11)
ti.metadata = read_json(data)
tag = read_tag(data)
if tag != LITERAL_NONE:
Expand Down Expand Up @@ -4882,15 +4988,18 @@ def set_flags(node: Node, flags: list[str]) -> None:
setattr(node, name, True)


def write_flags(data: WriteBuffer, node: SymbolNode, flags: list[str]) -> None:
for flag in flags:
write_bool(data, getattr(node, flag))
def write_flags(data: WriteBuffer, flags: list[bool]) -> None:
assert len(flags) <= 26, "This many flags not supported yet"
packed = 0
for i, flag in enumerate(flags):
if flag:
packed |= 1 << i
write_int(data, packed)


def read_flags(data: ReadBuffer, node: SymbolNode, flags: list[str]) -> None:
for flag in flags:
if read_bool(data):
setattr(node, flag, True)
def read_flags(data: ReadBuffer, num_flags: int) -> list[bool]:
packed = read_int(data)
return [(packed & (1 << i)) != 0 for i in range(num_flags)]


def get_member_expr_fullname(expr: MemberExpr) -> str | None:
Expand Down