Skip to content

Commit

Permalink
Upgrade mypy to 1.13.0 (#7978)
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Nov 10, 2024
1 parent 6f3f265 commit c386471
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions edb/edgeql/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def _trace_item_layout(
obj = local_obj

assert fq_name is not None
PointerType: type[qltracer.Pointer]

if isinstance(node, qlast.BasedOnTuple):
bases = []
Expand Down
2 changes: 1 addition & 1 deletion edb/ir/staeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def evaluate_SliceIndirection(

base, start, stop = vals

value = base[start:stop]
value = base[start:stop] # type: ignore[index]
return _process_op_result(
value, slice.expr.typeref, schema, span=slice.span)

Expand Down
2 changes: 1 addition & 1 deletion edb/schema/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _apply_field_ast(
op.new_value.resolve(schema)
if isinstance(op.new_value, so.ObjectShell)
else op.new_value)

assert isinstance(new_type, s_types.Type)
new_type_ast = utils.typeref_to_ast(schema, op.new_value)
cast_expr = None
# If the type isn't assignment castable, generate a
Expand Down
3 changes: 1 addition & 2 deletions edb/schema/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,10 +2401,9 @@ def __reduce__(self) -> Tuple[
else:
typeargs = types[0] if len(types) == 1 else types
attrs = {k: getattr(self, k) for k in self.__slots__ if k != '_ids'}
# Mypy fails to resolve typeargs properly
return (
cls.__restore__,
(typeargs, tuple(self._ids), attrs) # type: ignore
(typeargs, tuple(self._ids), attrs)
)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions edb/schema/referencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ def derive_ref(

cmdcls = sd.AlterObject if existing is not None else sd.CreateObject
cmd: sd.ObjectCommand[ReferencedInheritingObjectT] = (
sd.get_object_delta_command(
sd.get_object_delta_command( # type: ignore[type-var, assignment]
objtype=type(self),
cmdtype=cmdcls, # type: ignore[arg-type]
cmdtype=cmdcls,
schema=schema,
name=derived_name,
)
Expand Down
2 changes: 1 addition & 1 deletion edb/server/protocol/server_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def default(self, obj: Any) -> Any:
return list(obj)
if isinstance(obj, immutables.Map):
return dict(obj.items())
if dataclasses.is_dataclass(obj):
if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
return dataclasses.asdict(obj)
if isinstance(obj, statypes.Duration):
return obj.to_iso8601()
Expand Down
22 changes: 17 additions & 5 deletions edb/tools/mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import mypy.plugin as mypy_plugin
from mypy import mro
from mypy import nodes
from mypy import options as mypy_options
from mypy import types
from mypy import semanal
from mypy import typevars as mypy_typevars
from mypy import semanal_shared as mypy_semanal
from mypy.plugins import common as mypy_helpers
from mypy.server import trigger as mypy_trigger

Expand Down Expand Up @@ -71,12 +73,14 @@ def handle_schema_class(self, ctx: mypy_plugin.ClassDefContext):
transformers.append(
SchemaClassTransformer(
ctx,
self.options,
field_makers={'edb.schema.objects.SchemaField'},
)
)
transformers.append(
StructTransformer(
ctx,
self.options,
field_makers={'edb.schema.objects.Field'},
)
)
Expand All @@ -85,6 +89,7 @@ def handle_schema_class(self, ctx: mypy_plugin.ClassDefContext):
transformers.append(
StructTransformer(
ctx,
self.options,
field_makers={'edb.common.struct.Field'},
)
)
Expand All @@ -93,6 +98,7 @@ def handle_schema_class(self, ctx: mypy_plugin.ClassDefContext):
transformers.append(
ASTClassTransformer(
ctx,
self.options,
)
)

Expand Down Expand Up @@ -206,8 +212,10 @@ class BaseTransformer:
def __init__(
self,
ctx: mypy_plugin.ClassDefContext,
options: mypy_options.Options,
) -> None:
self._ctx = ctx
self._options = options

def transform(self):
ctx = self._ctx
Expand Down Expand Up @@ -344,8 +352,8 @@ def _synthesize_init(self, fields: List[Field]) -> None:
# var bounds), defer. If we skip deferring and stick something
# in our symbol table anyway, we'll get in trouble. (Arguably
# plugins.common ought to help us with this, but oh well.)
self_type = mypy_helpers.fill_typevars(cls_info)
if semanal.has_placeholder(self_type):
self_type = mypy_typevars.fill_typevars(cls_info)
if mypy_semanal.has_placeholder(self_type):
raise DeferException

if (
Expand All @@ -368,9 +376,10 @@ class BaseStructTransformer(BaseTransformer):
def __init__(
self,
ctx: mypy_plugin.ClassDefContext,
options: mypy_options.Options,
field_makers: AbstractSet[str],
) -> None:
super().__init__(ctx)
super().__init__(ctx, options)
self._field_makers = field_makers

def _field_from_field_def(
Expand Down Expand Up @@ -417,7 +426,10 @@ def _field_from_field_def(

if ftype is None:
try:
un_type = exprtotype.expr_to_unanalyzed_type(type_arg)
un_type = exprtotype.expr_to_unanalyzed_type(
type_arg,
options=self._options,
)
except exprtotype.TypeTranslationError:
ctx.api.fail('Cannot resolve schema field type', type_arg)
else:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test = [
'MarkupSafe~=1.1',
'PyYAML~=6.0',

'mypy~=1.10.0',
'mypy[faster-cache] ~= 1.13.0',
# mypy stub packages; when updating, you can use mypy --install-types
# to install stub packages and then pip freeze to read out the specifier
'types-docutils~=0.17.0,<0.17.6', # incomplete nodes.document.__init__
Expand Down

0 comments on commit c386471

Please sign in to comment.