Skip to content

Commit a6fb399

Browse files
chore: Make condition_index optional. Also added some scripts for local dev. (#223)
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent a1583f6 commit a6fb399

File tree

7 files changed

+71
-3
lines changed

7 files changed

+71
-3
lines changed

bin/build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/build
3+
#/ Description: Runs linter and mypy
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
flake8 posthog --ignore E501,W503
8+
mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter

bin/fmt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/fmt
3+
#/ Description: Formats and lints the code
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
if [[ "$1" == "--check" ]]; then
8+
black --check .
9+
isort --check-only .
10+
else
11+
black .
12+
isort .
13+
fi

bin/helpers/_utils.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error() {
2+
echo "$@" >&2
3+
}
4+
5+
fatal() {
6+
error "$@"
7+
exit 1
8+
}
9+
10+
set_source_and_root_dir() {
11+
{ set +x; } 2>/dev/null
12+
source_dir="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
13+
root_dir=$(cd "$source_dir" && cd ../ && pwd)
14+
cd "$root_dir"
15+
}

bin/setup

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/setup
3+
#/ Description: Sets up the dependencies needed to develop this project
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
if [ ! -d "env" ]; then
8+
python3 -m venv env
9+
fi
10+
source env/bin/activate
11+
pip install -e ".[dev,test]"

bin/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/test
3+
#/ Description: Runs all the unit tests for this project
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
pytest

posthog/test/test_feature_flags.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,21 @@ def test_capture_is_called_with_flag_details(self, patch_flags, patch_capture):
23572357
"id": 23,
23582358
"version": 42,
23592359
},
2360-
}
2360+
},
2361+
"false-flag": {
2362+
"key": "false-flag",
2363+
"enabled": False,
2364+
"variant": None,
2365+
"reason": {
2366+
"code": "no_matching_condition",
2367+
"description": "No matching condition",
2368+
"condition_index": None,
2369+
},
2370+
"metadata": {
2371+
"id": 1,
2372+
"version": 2,
2373+
},
2374+
},
23612375
},
23622376
"requestId": "18043bf7-9cf6-44cd-b959-9662ee20d371",
23632377
}

posthog/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@dataclass(frozen=True)
88
class FlagReason:
99
code: str
10-
condition_index: int
10+
condition_index: Optional[int]
1111
description: str
1212

1313
@classmethod
@@ -16,7 +16,7 @@ def from_json(cls, resp: Any) -> Optional["FlagReason"]:
1616
return None
1717
return cls(
1818
code=resp.get("code", ""),
19-
condition_index=resp.get("condition_index", 0),
19+
condition_index=resp.get("condition_index"),
2020
description=resp.get("description", ""),
2121
)
2222

0 commit comments

Comments
 (0)