Skip to content

Commit a8f06c8

Browse files
authored
[mypyc] Refactor: extract function related genops to new modules (python#8410)
The changes are fairly minimal beyond moving things around. There's more refactoring that can be done later, such as removing the import cycle.
1 parent 39e96f5 commit a8f06c8

File tree

5 files changed

+1526
-1388
lines changed

5 files changed

+1526
-1388
lines changed

mypyc/genclass.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
)
2121
from mypyc.ops_dict import dict_set_item_op, new_dict_op
2222
from mypyc.ops_tuple import new_tuple_op
23-
from mypyc.genopsutil import is_dataclass_decorator, get_func_def, is_dataclass
23+
from mypyc.genopsutil import (
24+
is_dataclass_decorator, get_func_def, is_dataclass, is_constant, add_self_to_env
25+
)
2426
from mypyc.common import SELF_NAME
2527

2628
MYPY = False
@@ -316,12 +318,12 @@ def generate_attr_defaults(self, cdef: ClassDef) -> None:
316318
self.builder.ret_types[-1] = bool_rprimitive
317319

318320
rt_args = (RuntimeArg(SELF_NAME, RInstance(cls)),)
319-
self_var = self.builder.read(self.builder.add_self_to_env(cls), -1)
321+
self_var = self.builder.read(add_self_to_env(self.builder.environment, cls), -1)
320322

321323
for stmt in default_assignments:
322324
lvalue = stmt.lvalues[0]
323325
assert isinstance(lvalue, NameExpr)
324-
if not stmt.is_final_def and not self.builder.is_constant(stmt.rvalue):
326+
if not stmt.is_final_def and not is_constant(stmt.rvalue):
325327
self.builder.warning('Unsupported default attribute value', stmt.rvalue.line)
326328

327329
# If the attribute is initialized to None and type isn't optional,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy