Skip to content

Commit

Permalink
Remove quotes from annotations (#13407)
Browse files Browse the repository at this point in the history
With #13391 (adding `from __future__ import annotations` everywhere), it's now possible to remove the quotes from annotations. Change generated with `pyupgrade` and excluding unrelated changes.
  • Loading branch information
cdce8p authored Aug 13, 2022
1 parent dc9c304 commit 3a13b8e
Show file tree
Hide file tree
Showing 23 changed files with 170 additions and 170 deletions.
42 changes: 21 additions & 21 deletions mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(
self.context = context
self.init_type = init_type

def argument(self, ctx: "mypy.plugin.ClassDefContext") -> Argument:
def argument(self, ctx: mypy.plugin.ClassDefContext) -> Argument:
"""Return this attribute as an argument to __init__."""
assert self.init

Expand Down Expand Up @@ -169,7 +169,7 @@ def serialize(self) -> JsonDict:
@classmethod
def deserialize(
cls, info: TypeInfo, data: JsonDict, api: SemanticAnalyzerPluginInterface
) -> "Attribute":
) -> Attribute:
"""Return the Attribute that was serialized."""
raw_init_type = data["init_type"]
init_type = deserialize_and_fixup_type(raw_init_type, api) if raw_init_type else None
Expand Down Expand Up @@ -200,7 +200,7 @@ def expand_typevar_from_subtype(self, sub_type: TypeInfo) -> None:
self.init_type = None


def _determine_eq_order(ctx: "mypy.plugin.ClassDefContext") -> bool:
def _determine_eq_order(ctx: mypy.plugin.ClassDefContext) -> bool:
"""
Validate the combination of *cmp*, *eq*, and *order*. Derive the effective
value of order.
Expand Down Expand Up @@ -230,7 +230,7 @@ def _determine_eq_order(ctx: "mypy.plugin.ClassDefContext") -> bool:


def _get_decorator_optional_bool_argument(
ctx: "mypy.plugin.ClassDefContext", name: str, default: Optional[bool] = None
ctx: mypy.plugin.ClassDefContext, name: str, default: Optional[bool] = None
) -> Optional[bool]:
"""Return the Optional[bool] argument for the decorator.
Expand All @@ -253,7 +253,7 @@ def _get_decorator_optional_bool_argument(
return default


def attr_tag_callback(ctx: "mypy.plugin.ClassDefContext") -> None:
def attr_tag_callback(ctx: mypy.plugin.ClassDefContext) -> None:
"""Record that we have an attrs class in the main semantic analysis pass.
The later pass implemented by attr_class_maker_callback will use this
Expand All @@ -264,7 +264,7 @@ def attr_tag_callback(ctx: "mypy.plugin.ClassDefContext") -> None:


def attr_class_maker_callback(
ctx: "mypy.plugin.ClassDefContext",
ctx: mypy.plugin.ClassDefContext,
auto_attribs_default: Optional[bool] = False,
frozen_default: bool = False,
) -> bool:
Expand Down Expand Up @@ -334,7 +334,7 @@ def attr_class_maker_callback(
return True


def _get_frozen(ctx: "mypy.plugin.ClassDefContext", frozen_default: bool) -> bool:
def _get_frozen(ctx: mypy.plugin.ClassDefContext, frozen_default: bool) -> bool:
"""Return whether this class is frozen."""
if _get_decorator_bool_argument(ctx, "frozen", frozen_default):
return True
Expand All @@ -346,7 +346,7 @@ def _get_frozen(ctx: "mypy.plugin.ClassDefContext", frozen_default: bool) -> boo


def _analyze_class(
ctx: "mypy.plugin.ClassDefContext", auto_attribs: Optional[bool], kw_only: bool
ctx: mypy.plugin.ClassDefContext, auto_attribs: Optional[bool], kw_only: bool
) -> List[Attribute]:
"""Analyze the class body of an attr maker, its parents, and return the Attributes found.
Expand Down Expand Up @@ -429,7 +429,7 @@ def _add_empty_metadata(info: TypeInfo) -> None:
info.metadata["attrs"] = {"attributes": [], "frozen": False}


def _detect_auto_attribs(ctx: "mypy.plugin.ClassDefContext") -> bool:
def _detect_auto_attribs(ctx: mypy.plugin.ClassDefContext) -> bool:
"""Return whether auto_attribs should be enabled or disabled.
It's disabled if there are any unannotated attribs()
Expand Down Expand Up @@ -459,7 +459,7 @@ def _detect_auto_attribs(ctx: "mypy.plugin.ClassDefContext") -> bool:


def _attributes_from_assignment(
ctx: "mypy.plugin.ClassDefContext", stmt: AssignmentStmt, auto_attribs: bool, kw_only: bool
ctx: mypy.plugin.ClassDefContext, stmt: AssignmentStmt, auto_attribs: bool, kw_only: bool
) -> Iterable[Attribute]:
"""Return Attribute objects that are created by this assignment.
Expand Down Expand Up @@ -525,7 +525,7 @@ def _cleanup_decorator(stmt: Decorator, attr_map: Dict[str, Attribute]) -> None:


def _attribute_from_auto_attrib(
ctx: "mypy.plugin.ClassDefContext",
ctx: mypy.plugin.ClassDefContext,
kw_only: bool,
lhs: NameExpr,
rvalue: Expression,
Expand All @@ -541,7 +541,7 @@ def _attribute_from_auto_attrib(


def _attribute_from_attrib_maker(
ctx: "mypy.plugin.ClassDefContext",
ctx: mypy.plugin.ClassDefContext,
auto_attribs: bool,
kw_only: bool,
lhs: NameExpr,
Expand Down Expand Up @@ -608,7 +608,7 @@ def _attribute_from_attrib_maker(


def _parse_converter(
ctx: "mypy.plugin.ClassDefContext", converter_expr: Optional[Expression]
ctx: mypy.plugin.ClassDefContext, converter_expr: Optional[Expression]
) -> Optional[Converter]:
"""Return the Converter object from an Expression."""
# TODO: Support complex converters, e.g. lambdas, calls, etc.
Expand Down Expand Up @@ -709,7 +709,7 @@ def _parse_assignments(
return lvalues, rvalues


def _add_order(ctx: "mypy.plugin.ClassDefContext", adder: "MethodAdder") -> None:
def _add_order(ctx: mypy.plugin.ClassDefContext, adder: MethodAdder) -> None:
"""Generate all the ordering methods for this class."""
bool_type = ctx.api.named_type("builtins.bool")
object_type = ctx.api.named_type("builtins.object")
Expand All @@ -730,7 +730,7 @@ def _add_order(ctx: "mypy.plugin.ClassDefContext", adder: "MethodAdder") -> None
adder.add_method(method, args, bool_type, self_type=tvd, tvd=tvd)


def _make_frozen(ctx: "mypy.plugin.ClassDefContext", attributes: List[Attribute]) -> None:
def _make_frozen(ctx: mypy.plugin.ClassDefContext, attributes: List[Attribute]) -> None:
"""Turn all the attributes into properties to simulate frozen classes."""
for attribute in attributes:
if attribute.name in ctx.cls.info.names:
Expand All @@ -749,7 +749,7 @@ def _make_frozen(ctx: "mypy.plugin.ClassDefContext", attributes: List[Attribute]


def _add_init(
ctx: "mypy.plugin.ClassDefContext", attributes: List[Attribute], adder: "MethodAdder"
ctx: mypy.plugin.ClassDefContext, attributes: List[Attribute], adder: MethodAdder
) -> None:
"""Generate an __init__ method for the attributes and add it to the class."""
# Convert attributes to arguments with kw_only arguments at the end of
Expand Down Expand Up @@ -781,10 +781,10 @@ def _add_init(


def _add_attrs_magic_attribute(
ctx: "mypy.plugin.ClassDefContext", attrs: "List[Tuple[str, Optional[Type]]]"
ctx: mypy.plugin.ClassDefContext, attrs: List[Tuple[str, Optional[Type]]]
) -> None:
any_type = AnyType(TypeOfAny.explicit)
attributes_types: "List[Type]" = [
attributes_types: List[Type] = [
ctx.api.named_type_or_none("attr.Attribute", [attr_type or any_type]) or any_type
for _, attr_type in attrs
]
Expand Down Expand Up @@ -814,12 +814,12 @@ def _add_attrs_magic_attribute(
)


def _add_slots(ctx: "mypy.plugin.ClassDefContext", attributes: List[Attribute]) -> None:
def _add_slots(ctx: mypy.plugin.ClassDefContext, attributes: List[Attribute]) -> None:
# Unlike `@dataclasses.dataclass`, `__slots__` is rewritten here.
ctx.cls.info.slots = {attr.name for attr in attributes}


def _add_match_args(ctx: "mypy.plugin.ClassDefContext", attributes: List[Attribute]) -> None:
def _add_match_args(ctx: mypy.plugin.ClassDefContext, attributes: List[Attribute]) -> None:
if (
"__match_args__" not in ctx.cls.info.names
or ctx.cls.info.names["__match_args__"].plugin_generated
Expand All @@ -844,7 +844,7 @@ class MethodAdder:

# TODO: Combine this with the code build_namedtuple_typeinfo to support both.

def __init__(self, ctx: "mypy.plugin.ClassDefContext") -> None:
def __init__(self, ctx: mypy.plugin.ClassDefContext) -> None:
self.ctx = ctx
self.self_type = fill_typevars(ctx.cls.info)

Expand Down
16 changes: 8 additions & 8 deletions mypy/plugins/ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def _find_simplecdata_base_arg(
tp: Instance, api: "mypy.plugin.CheckerPluginInterface"
tp: Instance, api: mypy.plugin.CheckerPluginInterface
) -> Optional[ProperType]:
"""Try to find a parametrized _SimpleCData in tp's bases and return its single type argument.
Expand All @@ -42,7 +42,7 @@ def _find_simplecdata_base_arg(
return None


def _autoconvertible_to_cdata(tp: Type, api: "mypy.plugin.CheckerPluginInterface") -> Type:
def _autoconvertible_to_cdata(tp: Type, api: mypy.plugin.CheckerPluginInterface) -> Type:
"""Get a type that is compatible with all types that can be implicitly converted to the given
CData type.
Expand Down Expand Up @@ -110,7 +110,7 @@ def _get_array_element_type(tp: Type) -> Optional[ProperType]:
return None


def array_constructor_callback(ctx: "mypy.plugin.FunctionContext") -> Type:
def array_constructor_callback(ctx: mypy.plugin.FunctionContext) -> Type:
"""Callback to provide an accurate signature for the ctypes.Array constructor."""
# Extract the element type from the constructor's return type, i. e. the type of the array
# being constructed.
Expand Down Expand Up @@ -144,7 +144,7 @@ def array_constructor_callback(ctx: "mypy.plugin.FunctionContext") -> Type:
return ctx.default_return_type


def array_getitem_callback(ctx: "mypy.plugin.MethodContext") -> Type:
def array_getitem_callback(ctx: mypy.plugin.MethodContext) -> Type:
"""Callback to provide an accurate return type for ctypes.Array.__getitem__."""
et = _get_array_element_type(ctx.type)
if et is not None:
Expand All @@ -164,7 +164,7 @@ def array_getitem_callback(ctx: "mypy.plugin.MethodContext") -> Type:
return ctx.default_return_type


def array_setitem_callback(ctx: "mypy.plugin.MethodSigContext") -> CallableType:
def array_setitem_callback(ctx: mypy.plugin.MethodSigContext) -> CallableType:
"""Callback to provide an accurate signature for ctypes.Array.__setitem__."""
et = _get_array_element_type(ctx.type)
if et is not None:
Expand All @@ -186,7 +186,7 @@ def array_setitem_callback(ctx: "mypy.plugin.MethodSigContext") -> CallableType:
return ctx.default_signature


def array_iter_callback(ctx: "mypy.plugin.MethodContext") -> Type:
def array_iter_callback(ctx: mypy.plugin.MethodContext) -> Type:
"""Callback to provide an accurate return type for ctypes.Array.__iter__."""
et = _get_array_element_type(ctx.type)
if et is not None:
Expand All @@ -195,7 +195,7 @@ def array_iter_callback(ctx: "mypy.plugin.MethodContext") -> Type:
return ctx.default_return_type


def array_value_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
def array_value_callback(ctx: mypy.plugin.AttributeContext) -> Type:
"""Callback to provide an accurate type for ctypes.Array.value."""
et = _get_array_element_type(ctx.type)
if et is not None:
Expand All @@ -218,7 +218,7 @@ def array_value_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
return ctx.default_attr_type


def array_raw_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
def array_raw_callback(ctx: mypy.plugin.AttributeContext) -> Type:
"""Callback to provide an accurate type for ctypes.Array.raw."""
et = _get_array_element_type(ctx.type)
if et is not None:
Expand Down
2 changes: 1 addition & 1 deletion mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def serialize(self) -> JsonDict:
@classmethod
def deserialize(
cls, info: TypeInfo, data: JsonDict, api: SemanticAnalyzerPluginInterface
) -> "DataclassAttribute":
) -> DataclassAttribute:
data = data.copy()
if data.get("kw_only") is None:
data["kw_only"] = False
Expand Down
6 changes: 3 additions & 3 deletions mypy/plugins/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}


def enum_name_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
def enum_name_callback(ctx: mypy.plugin.AttributeContext) -> Type:
"""This plugin refines the 'name' attribute in enums to act as if
they were declared to be final.
Expand Down Expand Up @@ -68,7 +68,7 @@ def _first(it: Iterable[_T]) -> Optional[_T]:


def _infer_value_type_with_auto_fallback(
ctx: "mypy.plugin.AttributeContext", proper_type: Optional[ProperType]
ctx: mypy.plugin.AttributeContext, proper_type: Optional[ProperType]
) -> Optional[Type]:
"""Figure out the type of an enum value accounting for `auto()`.
Expand Down Expand Up @@ -117,7 +117,7 @@ def _implements_new(info: TypeInfo) -> bool:
return type_with_new.fullname not in ("enum.Enum", "enum.IntEnum", "enum.StrEnum")


def enum_value_callback(ctx: "mypy.plugin.AttributeContext") -> Type:
def enum_value_callback(ctx: mypy.plugin.AttributeContext) -> Type:
"""This plugin refines the 'value' attribute in enums to refer to
the original underlying value. For example, suppose we have the
following:
Expand Down
2 changes: 1 addition & 1 deletion mypy/server/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def __init__(
self,
type_map: Dict[Expression, Type],
python_version: Tuple[int, int],
alias_deps: "DefaultDict[str, Set[str]]",
alias_deps: DefaultDict[str, Set[str]],
options: Optional[Options] = None,
) -> None:
self.scope = Scope()
Expand Down
20 changes: 10 additions & 10 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DeleteFile(NamedTuple):
FileOperation = Union[UpdateFile, DeleteFile]


def parse_test_case(case: "DataDrivenTestCase") -> None:
def parse_test_case(case: DataDrivenTestCase) -> None:
"""Parse and prepare a single case from suite with test case descriptions.
This method is part of the setup phase, just before the test case is run.
Expand Down Expand Up @@ -216,7 +216,7 @@ class DataDrivenTestCase(pytest.Item):
"""Holds parsed data-driven test cases, and handles directory setup and teardown."""

# Override parent member type
parent: "DataSuiteCollector"
parent: DataSuiteCollector

input: List[str]
output: List[str] # Output for the first pass
Expand Down Expand Up @@ -244,8 +244,8 @@ class DataDrivenTestCase(pytest.Item):

def __init__(
self,
parent: "DataSuiteCollector",
suite: "DataSuite",
parent: DataSuiteCollector,
suite: DataSuite,
file: str,
name: str,
writescache: bool,
Expand Down Expand Up @@ -583,7 +583,7 @@ def pytest_addoption(parser: Any) -> None:

# This function name is special to pytest. See
# http://doc.pytest.org/en/latest/writing_plugins.html#collection-hooks
def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> "Optional[Any]":
def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> Optional[Any]:
"""Called by pytest on each object in modules configured in conftest.py files.
collector is pytest.Collector, returns Optional[pytest.Class]
Expand All @@ -601,8 +601,8 @@ def pytest_pycollect_makeitem(collector: Any, name: str, obj: object) -> "Option


def split_test_cases(
parent: "DataFileCollector", suite: "DataSuite", file: str
) -> Iterator["DataDrivenTestCase"]:
parent: DataFileCollector, suite: DataSuite, file: str
) -> Iterator[DataDrivenTestCase]:
"""Iterate over raw test cases in file, at collection time, ignoring sub items.
The collection phase is slow, so any heavy processing should be deferred to after
Expand Down Expand Up @@ -654,7 +654,7 @@ def split_test_cases(


class DataSuiteCollector(pytest.Class):
def collect(self) -> Iterator["DataFileCollector"]:
def collect(self) -> Iterator[DataFileCollector]:
"""Called by pytest on each of the object returned from pytest_pycollect_makeitem"""

# obj is the object for which pytest_pycollect_makeitem returned self.
Expand All @@ -679,10 +679,10 @@ class DataFileCollector(pytest.Collector):
@classmethod # We have to fight with pytest here:
def from_parent( # type: ignore[override]
cls, parent: DataSuiteCollector, *, name: str
) -> "DataFileCollector":
) -> DataFileCollector:
return super().from_parent(parent, name=name)

def collect(self) -> Iterator["DataDrivenTestCase"]:
def collect(self) -> Iterator[DataDrivenTestCase]:
yield from split_test_cases(
parent=self,
suite=self.parent.obj,
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
CONNECTION_NAME = "dmypy-test-ipc"


def server(msg: str, q: "Queue[str]") -> None:
def server(msg: str, q: Queue[str]) -> None:
server = IPCServer(CONNECTION_NAME)
q.put(server.connection_name)
data = b""
Expand Down
2 changes: 1 addition & 1 deletion mypyc/analysis/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def cleanup_cfg(blocks: List[BasicBlock]) -> None:


class AnalysisResult(Generic[T]):
def __init__(self, before: "AnalysisDict[T]", after: "AnalysisDict[T]") -> None:
def __init__(self, before: AnalysisDict[T], after: AnalysisDict[T]) -> None:
self.before = before
self.after = after

Expand Down
2 changes: 1 addition & 1 deletion mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def emit_label(self, label: Union[BasicBlock, str]) -> None:
# Extra semicolon prevents an error when the next line declares a tempvar
self.fragments.append(f"{text}: ;\n")

def emit_from_emitter(self, emitter: "Emitter") -> None:
def emit_from_emitter(self, emitter: Emitter) -> None:
self.fragments.extend(emitter.fragments)

def emit_printf(self, fmt: str, *args: str) -> None:
Expand Down
Loading

0 comments on commit 3a13b8e

Please sign in to comment.