Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pyupgrade on the sources #14985

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Mypy documentation build configuration file, created by
# sphinx-quickstart on Sun Sep 14 19:50:35 2014.
#
Expand Down
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def has_no_attr(
)
else:
self.fail(
'{} has no attribute "{}"{}'.format(format_type(original_type), member, extra),
f'{format_type(original_type)} has no attribute "{member}"{extra}',
context,
code=codes.ATTR_DEFINED,
)
Expand Down
4 changes: 2 additions & 2 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pprint
import re
import sys
from typing import Any, Callable, Dict, Mapping, Pattern
from typing import Any, Callable, Mapping, Pattern
from typing_extensions import Final

from mypy import defaults
Expand Down Expand Up @@ -488,7 +488,7 @@ def compile_glob(self, s: str) -> Pattern[str]:
return re.compile(expr + "\\Z")

def select_options_affecting_cache(self) -> Mapping[str, object]:
result: Dict[str, object] = {}
result: dict[str, object] = {}
for opt in OPTIONS_AFFECTING_CACHE:
val = getattr(self, opt)
if opt in ("disabled_error_codes", "enabled_error_codes"):
Expand Down
4 changes: 2 additions & 2 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Iterator, Optional
from typing import Iterator
from typing_extensions import Final

from mypy import errorcodes, message_registry
Expand Down Expand Up @@ -118,7 +118,7 @@ def to_argument(self, current_info: TypeInfo) -> Argument:
kind=arg_kind,
)

def expand_type(self, current_info: TypeInfo) -> Optional[Type]:
def expand_type(self, current_info: TypeInfo) -> Type | None:
if self.type is not None and self.info.self_type is not None:
# In general, it is not safe to call `expand_type()` during semantic analyzis,
# however this plugin is called very late, so all types should be fully ready.
Expand Down
1 change: 0 additions & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import mypy.build
import mypy.modulefinder
import mypy.nodes
import mypy.state
import mypy.types
import mypy.version
Expand Down
2 changes: 1 addition & 1 deletion mypyc/analysis/attrdefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def update_always_defined_attrs_using_subclasses(cl: ClassIR, seen: set[ClassIR]
seen.add(cl)


def detect_undefined_bitmap(cl: ClassIR, seen: Set[ClassIR]) -> None:
def detect_undefined_bitmap(cl: ClassIR, seen: set[ClassIR]) -> None:
if cl.is_trait:
return

Expand Down
2 changes: 1 addition & 1 deletion mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def emit_unbox(
# TODO: Handle 'failure'
elif is_float_rprimitive(typ):
if declare_dest:
self.emit_line("double {};".format(dest))
self.emit_line(f"double {dest};")
# TODO: Don't use __float__ and __index__
self.emit_line(f"{dest} = PyFloat_AsDouble({src});")
self.emit_lines(
Expand Down
6 changes: 3 additions & 3 deletions mypyc/codegen/emitfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,10 @@ def visit_float_op(self, op: FloatOp) -> None:
lhs = self.reg(op.lhs)
rhs = self.reg(op.rhs)
if op.op != FloatOp.MOD:
self.emit_line("%s = %s %s %s;" % (dest, lhs, op.op_str[op.op], rhs))
self.emit_line(f"{dest} = {lhs} {op.op_str[op.op]} {rhs};")
else:
# TODO: This may set errno as a side effect, that is a little sketchy.
self.emit_line("%s = fmod(%s, %s);" % (dest, lhs, rhs))
self.emit_line(f"{dest} = fmod({lhs}, {rhs});")

def visit_float_neg(self, op: FloatNeg) -> None:
dest = self.reg(op)
Expand All @@ -694,7 +694,7 @@ def visit_float_comparison_op(self, op: FloatComparisonOp) -> None:
dest = self.reg(op)
lhs = self.reg(op.lhs)
rhs = self.reg(op.rhs)
self.emit_line("%s = %s %s %s;" % (dest, lhs, op.op_str[op.op], rhs))
self.emit_line(f"{dest} = {lhs} {op.op_str[op.op]} {rhs};")

def visit_load_mem(self, op: LoadMem) -> None:
dest = self.reg(op)
Expand Down
4 changes: 2 additions & 2 deletions mypyc/codegen/literals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import FrozenSet, List, Tuple, Union
from typing import FrozenSet, Tuple, Union
from typing_extensions import Final, TypeGuard

# Supported Python literal types. All tuple / frozenset items must have supported
Expand Down Expand Up @@ -140,7 +140,7 @@ def encoded_complex_values(self) -> list[str]:
def encoded_tuple_values(self) -> list[str]:
return self._encode_collection_values(self.tuple_literals)

def encoded_frozenset_values(self) -> List[str]:
def encoded_frozenset_values(self) -> list[str]:
return self._encode_collection_values(self.frozenset_literals)

def _encode_collection_values(
Expand Down
8 changes: 4 additions & 4 deletions mypyc/ir/class_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import List, NamedTuple, Optional
from typing import List, NamedTuple

from mypyc.common import PROPSET_PREFIX, JsonDict
from mypyc.ir.func_ir import FuncDecl, FuncIR, FuncSignature
Expand Down Expand Up @@ -70,10 +70,10 @@


class VTableMethod(NamedTuple):
cls: "ClassIR"
cls: ClassIR
name: str
method: FuncIR
shadow_method: Optional[FuncIR]
shadow_method: FuncIR | None


VTableEntries = List[VTableMethod]
Expand Down Expand Up @@ -192,7 +192,7 @@ def __init__(
# bitmap for types such as native ints that can't have a dedicated error
# value that doesn't overlap a valid value. The bitmap is used if the
# value of an attribute is the same as the error value.
self.bitmap_attrs: List[str] = []
self.bitmap_attrs: list[str] = []

def __repr__(self) -> str:
return (
Expand Down
2 changes: 1 addition & 1 deletion mypyc/ir/func_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def real_args(self) -> tuple[RuntimeArg, ...]:
return self.args[: -self.num_bitmap_args]
return self.args

def bound_sig(self) -> "FuncSignature":
def bound_sig(self) -> FuncSignature:
if self.num_bitmap_args:
return FuncSignature(self.args[1 : -self.num_bitmap_args], self.ret_type)
else:
Expand Down
18 changes: 9 additions & 9 deletions mypyc/ir/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from __future__ import annotations

from abc import abstractmethod
from typing import TYPE_CHECKING, Dict, Generic, List, NamedTuple, Sequence, TypeVar, Union
from typing import TYPE_CHECKING, Generic, List, NamedTuple, Sequence, TypeVar, Union
from typing_extensions import Final

from mypy_extensions import trait
Expand Down Expand Up @@ -1203,10 +1203,10 @@ def __init__(self, lhs: Value, rhs: Value, op: int, line: int = -1) -> None:
self.rhs = rhs
self.op = op

def sources(self) -> List[Value]:
def sources(self) -> list[Value]:
return [self.lhs, self.rhs]

def accept(self, visitor: "OpVisitor[T]") -> T:
def accept(self, visitor: OpVisitor[T]) -> T:
return visitor.visit_float_op(self)


Expand All @@ -1225,10 +1225,10 @@ def __init__(self, src: Value, line: int = -1) -> None:
self.type = float_rprimitive
self.src = src

def sources(self) -> List[Value]:
def sources(self) -> list[Value]:
return [self.src]

def accept(self, visitor: "OpVisitor[T]") -> T:
def accept(self, visitor: OpVisitor[T]) -> T:
return visitor.visit_float_neg(self)


Expand All @@ -1253,10 +1253,10 @@ def __init__(self, lhs: Value, rhs: Value, op: int, line: int = -1) -> None:
self.rhs = rhs
self.op = op

def sources(self) -> List[Value]:
def sources(self) -> list[Value]:
return [self.lhs, self.rhs]

def accept(self, visitor: "OpVisitor[T]") -> T:
def accept(self, visitor: OpVisitor[T]) -> T:
return visitor.visit_float_comparison_op(self)


Expand Down Expand Up @@ -1572,5 +1572,5 @@ def visit_keep_alive(self, op: KeepAlive) -> T:
# (Serialization and deserialization *will* be used for incremental
# compilation but so far it is not hooked up to anything.)
class DeserMaps(NamedTuple):
classes: Dict[str, "ClassIR"]
functions: Dict[str, "FuncIR"]
classes: dict[str, ClassIR]
functions: dict[str, FuncIR]
2 changes: 1 addition & 1 deletion mypyc/irbuild/specialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def translate_bool(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value


@specialize_function("builtins.float")
def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Optional[Value]:
def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS:
return None
arg = expr.args[0]
Expand Down
12 changes: 6 additions & 6 deletions mypyc/primitives/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from __future__ import annotations

from typing import List, NamedTuple, Optional, Tuple
from typing import NamedTuple
from typing_extensions import Final

from mypyc.ir.ops import StealsDescription
Expand All @@ -50,16 +50,16 @@

class CFunctionDescription(NamedTuple):
name: str
arg_types: List[RType]
arg_types: list[RType]
return_type: RType
var_arg_type: Optional[RType]
truncated_type: Optional[RType]
var_arg_type: RType | None
truncated_type: RType | None
c_function_name: str
error_kind: int
steals: StealsDescription
is_borrowed: bool
ordering: Optional[List[int]]
extra_int_constants: List[Tuple[int, RType]]
ordering: list[int] | None
extra_int_constants: list[tuple[int, RType]]
priority: int


Expand Down
1 change: 0 additions & 1 deletion mypyc/test-data/fixtures/testutil.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Simple support library for our run tests.

from contextlib import contextmanager
from collections.abc import Iterator
import math
from typing import (
Any, Iterator, TypeVar, Generator, Optional, List, Tuple, Sequence,
Expand Down