Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Fix style
  • Loading branch information
JukkaL committed Jun 10, 2024
commit 5d7972cd7aa980254bb8c17bf056f3e97848339e
4 changes: 3 additions & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,9 @@ def is_defined_type_param(self, name: str) -> bool:
return True
return False

def analyze_type_param(self, type_param: TypeParam, context: Context) -> TypeVarLikeExpr | None:
def analyze_type_param(
self, type_param: TypeParam, context: Context
) -> TypeVarLikeExpr | None:
fullname = self.qualified_name(type_param.name)
if type_param.upper_bound:
upper_bound = self.anal_type(type_param.upper_bound)
Expand Down
9 changes: 8 additions & 1 deletion mypyc/codegen/emitfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

from mypyc.analysis.blockfreq import frequently_executed_blocks
from mypyc.codegen.emit import DEBUG_ERRORS, Emitter, TracebackAndGotoHandler, c_array_initializer
from mypyc.common import MODULE_PREFIX, NATIVE_PREFIX, REG_PREFIX, STATIC_PREFIX, TYPE_PREFIX, TYPE_VAR_PREFIX
from mypyc.common import (
MODULE_PREFIX,
NATIVE_PREFIX,
REG_PREFIX,
STATIC_PREFIX,
TYPE_PREFIX,
TYPE_VAR_PREFIX,
)
from mypyc.ir.class_ir import ClassIR
from mypyc.ir.func_ir import FUNC_CLASSMETHOD, FUNC_STATICMETHOD, FuncDecl, FuncIR, all_values
from mypyc.ir.ops import (
Expand Down
3 changes: 1 addition & 2 deletions mypyc/codegen/emitmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
from mypyc.codegen.literals import Literals
from mypyc.common import (
MODULE_PREFIX,
TYPE_VAR_PREFIX,
PREFIX,
RUNTIME_C_FILES,
TOP_LEVEL_NAME,
TYPE_VAR_PREFIX,
shared_lib_name,
short_id_from_name,
use_vectorcall,
Expand Down Expand Up @@ -1075,7 +1075,6 @@ def declare_type_vars(self, module: str, type_var_names: list[str], emitter: Emi
)



def sort_classes(classes: list[tuple[str, ClassIR]]) -> list[tuple[str, ClassIR]]:
mod_name = {ir: name for name, ir in classes}
irs = [ir for _, ir in classes]
Expand Down
2 changes: 1 addition & 1 deletion mypyc/ir/module_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
# These are only visible in the module that defined them, so no need
# to serialize.
self.type_var_names = type_var_names

def serialize(self) -> JsonDict:
return {
"fullname": self.fullname,
Expand Down
13 changes: 9 additions & 4 deletions mypyc/irbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,17 @@ def load_final_static(
def init_type_var(self, value: Value, name: str, line: int) -> None:
unique_name = name + "___" + str(line)
self.type_var_names.append(unique_name)
self.add(InitStatic(value, unique_name, self.module_name,
namespace=NAMESPACE_TYPE_VAR))
self.add(InitStatic(value, unique_name, self.module_name, namespace=NAMESPACE_TYPE_VAR))

def load_type_var(self, name: str, line: int) -> Value:
return self.add(LoadStatic(object_rprimitive, name + "___" + str(line), self.module_name,
namespace=NAMESPACE_TYPE_VAR))
return self.add(
LoadStatic(
object_rprimitive,
name + "___" + str(line),
self.module_name,
namespace=NAMESPACE_TYPE_VAR,
)
)

def load_literal_value(self, val: int | str | bytes | float | complex | bool) -> Value:
"""Load value of a final name, class-level attribute, or constant folded expression."""
Expand Down
7 changes: 4 additions & 3 deletions mypyc/irbuild/classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,7 @@ def allocate_class(builder: IRBuilder, cdef: ClassDef) -> Value:
base_exprs = cdef.base_type_exprs + cdef.removed_base_type_exprs
new_style_type_args = cdef.type_args
if new_style_type_args:
bases = [
make_generic_base_class(builder, cdef.fullname, new_style_type_args, cdef.line)]
bases = [make_generic_base_class(builder, cdef.fullname, new_style_type_args, cdef.line)]
else:
bases = []

Expand Down Expand Up @@ -471,7 +470,9 @@ def allocate_class(builder: IRBuilder, cdef: ClassDef) -> Value:
return tp


def make_generic_base_class(builder: IRBuilder, fullname: str, type_args: list[TypeParam], line: int) -> Value:
def make_generic_base_class(
builder: IRBuilder, fullname: str, type_args: list[TypeParam], line: int
) -> Value:
"""Construct Generic[...] base class object for a new-style generic class (Python 3.12)."""
mod = builder.call_c(import_op, [builder.load_str("_typing")], line)
tvs = []
Expand Down
3 changes: 1 addition & 2 deletions mypyc/irbuild/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TupleExpr,
TypeApplication,
TypeInfo,
TypeVarExpr,
UnaryExpr,
Var,
)
Expand Down Expand Up @@ -102,8 +103,6 @@
from mypyc.primitives.str_ops import str_slice_op
from mypyc.primitives.tuple_ops import list_tuple_op, tuple_slice_op

# Name and attribute references
from mypy.nodes import TypeVarExpr

def transform_name_expr(builder: IRBuilder, expr: NameExpr) -> Value:
if isinstance(expr.node, TypeVarExpr) and expr.node.is_new_style:
Expand Down