Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Inject #839

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 2 additions & 4 deletions src/dodal/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from .coordination import group_uuid, inject
from .coordination import group_uuid
from .maths import in_micros, step_to_num
from .types import MsgGenerator, PlanGenerator
from .types import PlanGenerator

__all__ = [
"group_uuid",
"inject",
"in_micros",
"MsgGenerator",
"PlanGenerator",
"step_to_num",
]
24 changes: 0 additions & 24 deletions src/dodal/common/coordination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import uuid
from typing import Any

from dodal.common.types import Group

Expand All @@ -15,26 +14,3 @@ def group_uuid(name: str) -> Group:
readable_uid (Group): name appended with a unique string
"""
return f"{name}-{str(uuid.uuid4())[:6]}"


def inject(name: str) -> Any: # type: ignore
"""
Function to mark a defaulted argument of a plan as a reference to a device stored
in another context and not available to be referenced directly.
Bypasses type checking, returning x as Any and therefore valid as a default
argument, leaving handling to the context from which the plan is called.
Assumes that device.name is unique.
e.g. For a 1-dimensional scan, that is usually performed on a Movable with
name "stage_x"

def scan(x: Movable = inject("stage_x"), start: float = 0.0 ...)

Args:
name (str): Name of a Device to be fetched from an external context

Returns:
Any: name but without typing checking, valid as any default type

"""

return name
17 changes: 1 addition & 16 deletions tests/common/test_coordination.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from inspect import Parameter, signature

import pytest
from bluesky.protocols import Movable
from bluesky.utils import MsgGenerator

from dodal.common.coordination import group_uuid, inject
from dodal.common.coordination import group_uuid

static_uuid = "51aef931-33b4-4b33-b7ad-a8287f541202"

Expand All @@ -14,14 +10,3 @@ def test_group_uid(group: str):
gid = group_uuid(group)
assert gid.startswith(f"{group}-")
assert not gid.endswith(f"{group}-")


def test_type_checking_ignores_inject():
def example_function(x: Movable = inject("foo")) -> MsgGenerator: # noqa: B008
yield from {}

# These asserts are sanity checks
# the real test is whether this test passes type checking
x: Parameter = signature(example_function).parameters["x"]
assert x.annotation == Movable
assert x.default == "foo"
Loading