Skip to content

Commit

Permalink
removes redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Oct 26, 2024
1 parent 03a8bc5 commit 4174f2f
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions refinery/lib/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
Implements programmatic inlining, specifically for the units in `refinery.units.blockwise`.
"""
from __future__ import annotations
from typing import Any, Callable, Generator, Optional, Type, TypeVar, Union
from typing import Any, Callable, Generator, Optional, Type, TypeVar

import ast
import inspect
import functools
import sys

from ast import (
Assign,
BinOp,
BitAnd,
Bytes,
Call,
Constant,
Expr,
Expand All @@ -25,10 +22,8 @@
Load,
Name,
NodeTransformer,
Num,
Return,
Store,
Str,
Yield,
arg,
comprehension,
Expand Down Expand Up @@ -129,19 +124,8 @@ def apply_node_transformation(cls: Type[NodeTransformer]):
nonlocal code
code = ast.fix_missing_locations(cls().visit(code))

if sys.version_info >= (3, 8):
def constant(value):
return Constant(value=value)
else:
@functools.singledispatch
def constant(value: Union[int, str, bytes]):
raise NotImplementedError(F'The type {type(value).__name__} is not supported for inlining')
@constant.register # noqa
def _(value: bytes): return Bytes(s=value)
@constant.register
def _(value: int): return Num(n=value)
@constant.register
def _(value: str): return Str(s=value)
def constant(value):
return Constant(value=value)

@apply_node_transformation
class _(NodeTransformer):
Expand Down

0 comments on commit 4174f2f

Please sign in to comment.