Skip to content
Merged
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
4 changes: 2 additions & 2 deletions fiddle/_src/absl_flags/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ def value(self):
raise

elif command == "set":
utils.set_value(self._value, expression)
utils.set_value(self._value, expression) # pyrefly: ignore[bad-argument-type]
elif command == "fiddler":
self._value = self._apply_fiddler(self._value, expression)
self._value = self._apply_fiddler(self._value, expression) # pyrefly: ignore[bad-argument-type]
else:
raise AssertionError("Internal error; should not be reached.")
return self._value
Expand Down
2 changes: 1 addition & 1 deletion fiddle/_src/absl_flags/legacy_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _rewrite(arg: str) -> str:
explicit_name = 'fdl_tags_set'
_, arg = arg.split('.', maxsplit=1) # Strip --fdl. or --fdl_tag. prefix.
path, value = arg.split('=', maxsplit=1)
rewritten = f'--{explicit_name}={path}={value}'
rewritten = f'--{explicit_name}={path}={value}' # pyrefly: ignore[unbound-name]
logging.debug('Rewrote flag "%s" to "%s".', arg, rewritten)
return rewritten
else:
Expand Down
2 changes: 1 addition & 1 deletion fiddle/_src/absl_flags/sweep_flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(
@property
def value(self) -> Sequence[SweepItem]:
if self._value is None:
self._value = self._parse(self._multi_flag.value)
self._value = self._parse(self._multi_flag.value) # pyrefly: ignore[bad-argument-type]
return self._value

def _parse_call_expression(
Expand Down
2 changes: 1 addition & 1 deletion fiddle/_src/absl_flags/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def test_dotted_module_prefix_matching(self):
class C:
d = 42

sub_b.c = C
sub_b.c = C # pyrefly: ignore[missing-attribute]

sys.modules['a'] = parent_a
sys.modules['a.b'] = sub_b
Expand Down
2 changes: 1 addition & 1 deletion fiddle/_src/codegen/auto_config/code_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def to_stack(self) -> List[CallInstance]:
result = [self]
while current.parent is not None:
current = current.parent
result.append(current)
result.append(current) # pyrefly: ignore[bad-argument-type]
return list(reversed(result))

@arg_factory.supply_defaults
Expand Down
8 changes: 4 additions & 4 deletions fiddle/_src/codegen/auto_config/experimental_top_level_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,25 +206,25 @@ def code_generator(
ImportSymbols(),
TransformSubFixtures(),
]
passes.extend([
passes.extend([ # pyrefly: ignore[bad-argument-type]
LowerArgFactories(),
MoveSharedNodesToVariables(),
])
if max_expression_complexity is not None:
is_complex = complex_to_variables.more_complex_than(
max_expression_complexity
)
passes.append(MoveComplexNodesToVariables(is_complex=is_complex))
passes.append(MoveComplexNodesToVariables(is_complex=is_complex)) # pyrefly: ignore[bad-argument-type]
format_history = (
get_history_comments.format_history_for_buildable
if include_history
else make_symbolic_references.noop_history_comments
)
passes.extend([
passes.extend([ # pyrefly: ignore[bad-argument-type]
MakeSymbolicReferences(format_history=format_history),
IrToCst(),
])
return Codegen(passes=passes, debug_print=debug_print)
return Codegen(passes=passes, debug_print=debug_print) # pyrefly: ignore[bad-argument-type]


def auto_config_codegen(
Expand Down
2 changes: 1 addition & 1 deletion fiddle/_src/codegen/auto_config/ir_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _is_typing_or_generic(value: Any) -> bool:


def format_py_reference(value: Any) -> str:
module_name = inspect.getmodule(value).__name__
module_name = inspect.getmodule(value).__name__ # pyrefly: ignore[missing-attribute]
if module_name in ("fiddle._src.config", "fiddle._src.partial"):
module_name = "fdl"
cls_name = value.__qualname__
Expand Down
14 changes: 7 additions & 7 deletions fiddle/_src/codegen/auto_config/ir_to_cst.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _prepare_args_helper(
" please replace these objects in your input config, likely "
"with fdl.Config nodes."
)
elements.append(cst.Element(sub_value))
elements.append(cst.Element(sub_value)) # pyrefly: ignore[bad-argument-type]
return cst_cls(elements)
elif isinstance(value, dict):
elements = []
Expand All @@ -130,9 +130,9 @@ def _prepare_args_helper(
return cst.Attribute(value=base, attr=cst.Name(value.attribute))
elif isinstance(value, code_ir.ParameterizedTypeExpression):
return cst.Subscript(
value=code_for_expr(value.base_expression),
value=code_for_expr(value.base_expression), # pyrefly: ignore[bad-argument-type]
slice=[
cst.SubscriptElement(cst.Index(code_for_expr(param)))
cst.SubscriptElement(cst.Index(code_for_expr(param))) # pyrefly: ignore[bad-argument-type]
for param in value.param_expressions
],
)
Expand All @@ -151,7 +151,7 @@ def _prepare_args_helper(
)
args.extend(
_prepare_args_helper(
names, values, attr, history=value.history_comments
names, values, attr, history=value.history_comments # pyrefly: ignore[bad-argument-type]
)
)
if any_args_have_history:
Expand Down Expand Up @@ -223,20 +223,20 @@ def code_for_fn(
name = variable_decl.name.value
assign = cst.Assign(
targets=[cst.AssignTarget(target=cst.Name(name))],
value=code_for_expr(variable_decl.expression),
value=code_for_expr(variable_decl.expression), # pyrefly: ignore[bad-argument-type]
)
variable_lines.append(cst.SimpleStatementLine(body=[assign]))
body = cst.IndentedBlock(
body=[
*variable_lines,
cst.SimpleStatementLine(
body=[cst.Return(code_for_expr(fn.output_value))]
body=[cst.Return(code_for_expr(fn.output_value))] # pyrefly: ignore[bad-argument-type]
),
]
)
if fn.return_type_annotation:
returns = cst.Annotation(
annotation=code_for_expr(fn.return_type_annotation)
annotation=code_for_expr(fn.return_type_annotation) # pyrefly: ignore[bad-argument-type]
)
else:
returns = None
Expand Down
6 changes: 3 additions & 3 deletions fiddle/_src/codegen/auto_config/make_symbolic_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ def _handle_partial(
for name, arg_value in arguments.items():
if isinstance(arg_value, code_ir.ArgFactoryExpr):
arg_factory_args[name] = state.call(
arg_value.expression, daglish.Attr(name)
arg_value.expression, daglish.Attr(name) # pyrefly: ignore[bad-argument-type]
)
else:
regular_args[name] = state.call(arg_value, daglish.Attr(name))
regular_args[name] = state.call(arg_value, daglish.Attr(name)) # pyrefly: ignore[bad-argument-type]

for dict_of_args in (arg_factory_args, regular_args):
for arg in dict_of_args:
Expand Down Expand Up @@ -179,7 +179,7 @@ def traverse(value, state: daglish.State):
return code_ir.SymbolOrFixtureCall(
symbol_expression=ir_for_symbol,
positional_arg_expressions=[],
arg_expressions=config_lib.ordered_arguments(value),
arg_expressions=config_lib.ordered_arguments(value), # pyrefly: ignore[bad-argument-type]
history_comments=format_history(value),
)
elif isinstance(value, partial.Partial):
Expand Down
12 changes: 6 additions & 6 deletions fiddle/_src/codegen/auto_config/sub_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def _is_super_ancestor(
Returns:
A bool value that indicates if `ancestor` is a super ancestor of all nodes.
"""
nodes = list(nodes)
nodes = list(nodes) # pyrefly: ignore[bad-assignment]
if len(nodes) == 0: # pylint: disable=g-explicit-length-test
return False
if len(nodes) == 1:
if ancestor in nodes:
return True
all_parents = node_to_parents_by_id[nodes[0]]
all_parents = node_to_parents_by_id[nodes[0]] # pyrefly: ignore[bad-index]
if len(all_parents) == 1 and ancestor in all_parents:
return True
return _is_super_ancestor(ancestor, all_parents, node_to_parents_by_id)
Expand All @@ -98,11 +98,11 @@ def _find_least_common_ancestor(
) -> int:
"""Find the least common ancestor of all nodes."""

node_ids = list(node_ids)
node_ids = list(node_ids) # pyrefly: ignore[bad-assignment]
if len(node_ids) == 0: # pylint: disable=g-explicit-length-test
raise ValueError("Input nodes must not be empty.")
if len(node_ids) == 1:
return node_ids[0]
return node_ids[0] # pyrefly: ignore[bad-index]
if len(node_ids) == 2:
x, y = node_ids
if _is_super_ancestor(x, {y}, node_to_parents_by_id):
Expand All @@ -114,8 +114,8 @@ def _find_least_common_ancestor(
return _find_least_common_ancestor(
x_parents.union(y_parents), node_to_parents_by_id
)
first_two = set(node_ids[:2])
rest = set(node_ids[2:])
first_two = set(node_ids[:2]) # pyrefly: ignore[bad-index]
rest = set(node_ids[2:]) # pyrefly: ignore[bad-index]
first_two_ancestor = _find_least_common_ancestor(
first_two, node_to_parents_by_id
)
Expand Down
38 changes: 19 additions & 19 deletions fiddle/_src/codegen/codegen_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _cst_for_fiddler(func_name: str, param_name: str, body: List[cst.CSTNode],
name=cst.Name(func_name),
params=cst.Parameters(
params=[cst.Param(name=cst.Name(param_name), star='')]),
body=cst.IndentedBlock(body),
body=cst.IndentedBlock(body), # pyrefly: ignore[bad-argument-type]
leading_lines=[cst.EmptyLine()] if add_leading_blank_line else [])


Expand All @@ -237,7 +237,7 @@ def _cst_for_new_shared_value_variables(
statements.append(
cst.Assign(
targets=[cst.AssignTarget(target=cst.Name(name))],
value=pyval_to_cst(value)))
value=pyval_to_cst(value))) # pyrefly: ignore[bad-argument-type]
return [cst.SimpleStatementLine([stmt]) for stmt in statements]


Expand Down Expand Up @@ -368,24 +368,24 @@ def _cst_for_changes(diff: diffing.Diff, param_name: str,
new_value_cst = pyval_to_cst(change.new_value)
update_callable = cst.Expr(
cst.Call(
func=pyval_to_cst(mutate_buildable.update_callable),
args=[cst.Arg(parent_cst), cst.Arg(new_value_cst)],
func=pyval_to_cst(mutate_buildable.update_callable), # pyrefly: ignore[bad-argument-type]
args=[cst.Arg(parent_cst), cst.Arg(new_value_cst)], # pyrefly: ignore[bad-argument-type]
)
)

elif isinstance(change, diffing.DeleteValue):
deletes.append(cst.Del(target=child_cst))
deletes.append(cst.Del(target=child_cst)) # pyrefly: ignore[bad-argument-type]

elif isinstance(change, diffing.RemoveTag):
arg_name = change.target[-1].name
arg_name = change.target[-1].name # pyrefly: ignore[missing-attribute]
deletes.append(
cst.Expr(
cst.Call(
func=pyval_to_cst(tagging.remove_tag),
func=pyval_to_cst(tagging.remove_tag), # pyrefly: ignore[bad-argument-type]
args=[
cst.Arg(parent_cst),
cst.Arg(pyval_to_cst(arg_name)),
cst.Arg(pyval_to_cst(change.tag)),
cst.Arg(pyval_to_cst(arg_name)), # pyrefly: ignore[bad-argument-type]
cst.Arg(pyval_to_cst(change.tag)), # pyrefly: ignore[bad-argument-type]
],
)
)
Expand All @@ -395,18 +395,18 @@ def _cst_for_changes(diff: diffing.Diff, param_name: str,
new_value_cst = pyval_to_cst(change.new_value)
assigns.append(
cst.Assign(
targets=[cst.AssignTarget(child_cst)], value=new_value_cst))
targets=[cst.AssignTarget(child_cst)], value=new_value_cst)) # pyrefly: ignore[bad-argument-type]

elif isinstance(change, diffing.AddTag):
arg_name = change.target[-1].name
arg_name = change.target[-1].name # pyrefly: ignore[missing-attribute]
assigns.append(
cst.Expr(
value=cst.Call(
func=pyval_to_cst(tagging.add_tag),
func=pyval_to_cst(tagging.add_tag), # pyrefly: ignore[bad-argument-type]
args=[
cst.Arg(parent_cst),
cst.Arg(pyval_to_cst(arg_name)),
cst.Arg(pyval_to_cst(change.tag)),
cst.Arg(pyval_to_cst(arg_name)), # pyrefly: ignore[bad-argument-type]
cst.Arg(pyval_to_cst(change.tag)), # pyrefly: ignore[bad-argument-type]
],
)
)
Expand All @@ -433,17 +433,17 @@ def _cst_for_child(parent_cst: cst.CSTNode, child_path_elt: daglish.PathElement,
pyval_to_cst: A function used to convert Python values to CST.
"""
if isinstance(child_path_elt, daglish.Attr):
return cst.Attribute(value=parent_cst, attr=cst.Name(child_path_elt.name))
return cst.Attribute(value=parent_cst, attr=cst.Name(child_path_elt.name)) # pyrefly: ignore[bad-argument-type]
elif isinstance(child_path_elt, daglish.Index):
index_cst = pyval_to_cst(child_path_elt.index)
return cst.Subscript(
value=parent_cst,
slice=[cst.SubscriptElement(slice=cst.Index(index_cst))])
value=parent_cst, # pyrefly: ignore[bad-argument-type]
slice=[cst.SubscriptElement(slice=cst.Index(index_cst))]) # pyrefly: ignore[bad-argument-type]
elif isinstance(child_path_elt, daglish.Key):
key_cst = pyval_to_cst(child_path_elt.key)
return cst.Subscript(
value=parent_cst,
slice=[cst.SubscriptElement(slice=cst.Index(key_cst))])
value=parent_cst, # pyrefly: ignore[bad-argument-type]
slice=[cst.SubscriptElement(slice=cst.Index(key_cst))]) # pyrefly: ignore[bad-argument-type]
else:
raise ValueError(f'Unsupported PathElement {type(child_path_elt)}')

Expand Down
8 changes: 4 additions & 4 deletions fiddle/_src/codegen/import_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def parse_import(stmt: str) -> AnyImport:


def _get_import_name_node(node: AnyImport) -> cst.ImportAlias:
if len(node.names) != 1:
if len(node.names) != 1: # pyrefly: ignore[bad-argument-type]
raise ValueError(
f"CST nodes with more than 1 name are not supported; got {node}")
return node.names[0]
return node.names[0] # pyrefly: ignore[bad-index]


def get_import_name(node: AnyImport) -> str:
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_full_module_name(node: AnyImport) -> str:
name_str = _dummy_module_for_formatting.code_for_node(
_get_import_name_node(node).name)
if isinstance(node, cst.ImportFrom):
module_str = _dummy_module_for_formatting.code_for_node(node.module)
module_str = _dummy_module_for_formatting.code_for_node(node.module) # pyrefly: ignore[bad-argument-type]
return f"{module_str}.{name_str}"
else:
return name_str
Expand Down Expand Up @@ -230,7 +230,7 @@ def add(self, value: Any) -> str:
Returns:
Relative-qualified name for the instance.
"""
module_name = inspect.getmodule(value).__name__
module_name = inspect.getmodule(value).__name__ # pyrefly: ignore[missing-attribute]
if isinstance(value, enum.Enum):
value_qualname = value.__class__.__qualname__ + "." + value.name
else:
Expand Down
12 changes: 6 additions & 6 deletions fiddle/_src/codegen/legacy_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def traverse(child, state=None):
return state.map_children(child)
else:
return special_value_codegen.transform_py_value(child,
self.import_manager)
self.import_manager) # pyrefly: ignore[bad-argument-type]

lhs = assignment_path(lhs_var, lhs_path)
assignment = mini_ast.Assignment(lhs, repr(traverse(attr_value)))
Expand Down Expand Up @@ -208,12 +208,12 @@ def traverse(child, state: daglish.State):
mini_ast.Assignment(name, f"{buildable_subclass_str}({relname})")
]
for key, value in child.__arguments__.items():
path = [daglish.BuildableAttr(key)]
nodes.append(shared_manager.assign(name, path, value))
path = [daglish.BuildableAttr(key)] # pyrefly: ignore[bad-argument-type]
nodes.append(shared_manager.assign(name, path, value)) # pyrefly: ignore[bad-argument-type]

# `shared_manager` indexes by ID, so be careful to use the original DAG
# node `child`.
shared_manager.add(name, child, mini_ast.ImmediateAttrsBlock(nodes))
shared_manager.add(name, child, mini_ast.ImmediateAttrsBlock(nodes)) # pyrefly: ignore[bad-argument-type]

traverser = daglish.MemoizedTraversal(
traverse,
Expand Down Expand Up @@ -290,14 +290,14 @@ def handle_child_attr(value, state: daglish.State):
config_lib.Buildable) and value not in shared_manager:
deferred.append((value, full_path))
else:
nodes.append(shared_manager.assign("root", full_path, value))
nodes.append(shared_manager.assign("root", full_path, value)) # pyrefly: ignore[bad-argument-type]

if state.is_traversable(value) and not isinstance(value,
config_lib.Buildable):
state.flattened_map_children(value)

daglish.BasicTraversal.run(handle_child_attr, child)
main_tree_blocks.append(mini_ast.ImmediateAttrsBlock(nodes))
main_tree_blocks.append(mini_ast.ImmediateAttrsBlock(nodes)) # pyrefly: ignore[bad-argument-type]

# Recurses to configure sub-Buildable nodes.
for sub_child, sub_path in deferred:
Expand Down
Loading
Loading