apache / apache/hamilton

Clarify behavior of decorator ordering

Open
#57 0 comments 0 reactions 0 assignees View on GitHub
documentation migrated-from-old-repo
Dominant language
Jupyter Notebook
Stars
2.6k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

**Issue by [skrawcz](https://github.com/skrawcz)**
_Sunday Dec 18, 2022 at 01:28 GMT_
_Originally opened as https://github.com/stitchfix/hamilton/issues/249_

----

We need to make clear our philosophy and resolution method for functions such as:

```python
@extract_fields({'out_value1': int, 'out_value2': str})
@tag(test_key="test-value")
@check_output(data_type=dict, importance="fail")
@does(_dummy)
def uber_decorated_function(in_value1: int, in_value2: str) -> dict:
pass
```

Right now it is not clear, nor obvious.

# Current behavior
This is what the graph looks like:

![Screen Shot 2022-12-17 at 5 24 42 PM](https://user-images.githubusercontent.com/2328071/208272588-4cd00882-ac18-4bf4-b794-cf9f421774b1.png)

So it would be unexpected to see `check_output` over the output of `extract_fields`.

## Steps to replicate behavior
Function code:
```python
def _dummy(**values) -> dict:
return {f"out_{k.split('_')[1]}": v for k, v in values.items()}

@extract_fields({'out_value1': int, 'out_value2': str})
@tag(test_key="test-value")
@check_output(data_type=dict, importance="fail")
@does(_dummy)
def uber_decorated_function(in_value1: int, in_value2: str) -> dict:
pass
```

# Expected behavior
`check_output` should probably operate over what's directly underneath that.
`tag` similarly should apply to all? or just what's underneath?
`does` should apply to `uber_decorated_function`
`extract_fields` is the last thing that's applied?

# Additional context
Thoughts: can we create a linter that reorders decorators?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.