Skip to content

Commit 38683e8

Browse files
authored
Add mypy to CI (#189)
1 parent a5c8f62 commit 38683e8

File tree

5 files changed

+116
-3
lines changed

5 files changed

+116
-3
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ jobs:
1313
with:
1414
fetch-depth: 1
1515

16-
- name: Set up Python 3.8
16+
- name: Set up Python 3.11
1717
uses: actions/setup-python@v2
1818
with:
19-
python-version: 3.8
19+
python-version: 3.11.11
2020

2121
- uses: actions/cache@v3
2222
with:
@@ -42,6 +42,10 @@ jobs:
4242
run: |
4343
isort --check-only .
4444
45+
- name: Check types with mypy
46+
run: |
47+
mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter
48+
4549
tests:
4650
name: Python tests
4751
runs-on: ubuntu-latest

mypy-baseline.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
posthog/utils.py:0: error: Library stubs not installed for "six" [import-untyped]
2+
posthog/utils.py:0: error: Library stubs not installed for "dateutil.tz" [import-untyped]
3+
posthog/utils.py:0: error: Statement is unreachable [unreachable]
4+
posthog/utils.py:0: error: Argument 1 to "join" of "str" has incompatible type "AttributeError"; expected "Iterable[str]" [arg-type]
5+
posthog/request.py:0: error: Library stubs not installed for "requests" [import-untyped]
6+
posthog/request.py:0: note: Hint: "python3 -m pip install types-requests"
7+
posthog/request.py:0: error: Library stubs not installed for "dateutil.tz" [import-untyped]
8+
posthog/request.py:0: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
9+
posthog/consumer.py:0: error: Name "Empty" already defined (possibly by an import) [no-redef]
10+
posthog/consumer.py:0: error: Need type annotation for "items" (hint: "items: list[<type>] = ...") [var-annotated]
11+
posthog/consumer.py:0: error: Unsupported operand types for <= ("int" and "str") [operator]
12+
posthog/consumer.py:0: note: Right operand is of type "int | str"
13+
posthog/consumer.py:0: error: Unsupported operand types for < ("str" and "int") [operator]
14+
posthog/consumer.py:0: note: Left operand is of type "int | str"
15+
posthog/feature_flags.py:0: error: Library stubs not installed for "dateutil" [import-untyped]
16+
posthog/feature_flags.py:0: error: Library stubs not installed for "dateutil.relativedelta" [import-untyped]
17+
posthog/feature_flags.py:0: error: Unused "type: ignore" comment [unused-ignore]
18+
posthog/client.py:0: error: Library stubs not installed for "dateutil.tz" [import-untyped]
19+
posthog/client.py:0: note: Hint: "python3 -m pip install types-python-dateutil"
20+
posthog/client.py:0: note: (or run "mypy --install-types" to install all missing stub packages)
21+
posthog/client.py:0: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
22+
posthog/client.py:0: error: Library stubs not installed for "six" [import-untyped]
23+
posthog/client.py:0: note: Hint: "python3 -m pip install types-six"
24+
posthog/client.py:0: error: Name "queue" already defined (by an import) [no-redef]
25+
posthog/client.py:0: error: Need type annotation for "queue" [var-annotated]
26+
posthog/client.py:0: error: Item "None" of "Any | None" has no attribute "get" [union-attr]
27+
simulator.py:0: error: Unexpected keyword argument "anonymous_id" for "capture" [call-arg]
28+
posthog/__init__.py:0: note: "capture" defined here
29+
simulator.py:0: error: Unexpected keyword argument "anonymous_id" for "identify" [call-arg]
30+
posthog/__init__.py:0: note: "identify" defined here
31+
simulator.py:0: error: Unexpected keyword argument "traits" for "identify" [call-arg]
32+
posthog/__init__.py:0: note: "identify" defined here
33+
example.py:0: error: Statement is unreachable [unreachable]
34+
posthog/sentry/posthog_integration.py:0: error: Statement is unreachable [unreachable]
35+
posthog/ai/utils.py:0: error: Need type annotation for "output" (hint: "output: list[<type>] = ...") [var-annotated]
36+
posthog/ai/utils.py:0: error: Function "builtins.any" is not valid as a type [valid-type]
37+
posthog/ai/utils.py:0: note: Perhaps you meant "typing.Any" instead of "any"?
38+
posthog/ai/utils.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
39+
posthog/ai/utils.py:0: error: Function "builtins.any" is not valid as a type [valid-type]
40+
posthog/ai/utils.py:0: note: Perhaps you meant "typing.Any" instead of "any"?
41+
posthog/ai/utils.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
42+
sentry_django_example/sentry_django_example/settings.py:0: error: Need type annotation for "ALLOWED_HOSTS" (hint: "ALLOWED_HOSTS: list[<type>] = ...") [var-annotated]
43+
sentry_django_example/sentry_django_example/settings.py:0: error: Incompatible types in assignment (expression has type "str", variable has type "None") [assignment]
44+
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
45+
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
46+
posthog/ai/openai/openai_async.py:0: error: Unpacked dict entry 11 has incompatible type "dict[str, Any] | None"; expected "SupportsKeysAndGetItem[str, Any]" [dict-item]
47+
posthog/ai/openai/openai_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
48+
posthog/ai/openai/openai_async.py:0: error: Unpacked dict entry 8 has incompatible type "dict[str, Any] | None"; expected "SupportsKeysAndGetItem[str, Any]" [dict-item]
49+
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
50+
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
51+
posthog/ai/openai/openai.py:0: error: Unpacked dict entry 11 has incompatible type "dict[str, Any] | None"; expected "SupportsKeysAndGetItem[str, Any]" [dict-item]
52+
posthog/ai/openai/openai.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
53+
posthog/ai/openai/openai.py:0: error: Unpacked dict entry 8 has incompatible type "dict[str, Any] | None"; expected "SupportsKeysAndGetItem[str, Any]" [dict-item]
54+
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
55+
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
56+
posthog/ai/anthropic/anthropic_async.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
57+
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
58+
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
59+
posthog/ai/anthropic/anthropic.py:0: error: Incompatible types in assignment (expression has type "UUID", variable has type "str | None") [assignment]
60+
llm_observability_examples.py:0: error: Argument "posthog_client" to "OpenAI" has incompatible type Module; expected "Client" [arg-type]
61+
llm_observability_examples.py:0: error: Argument "posthog_client" to "AsyncOpenAI" has incompatible type Module; expected "Client" [arg-type]

mypy.ini

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[mypy]
2+
python_version = 3.11
3+
plugins =
4+
pydantic.mypy
5+
strict_optional = True
6+
no_implicit_optional = True
7+
warn_unused_ignores = True
8+
check_untyped_defs = True
9+
warn_unreachable = True
10+
strict_equality = True
11+
ignore_missing_imports = True
12+
13+
[mypy-django.*]
14+
ignore_missing_imports = True
15+
16+
[mypy-sentry_sdk.*]
17+
ignore_missing_imports = True
18+
19+
[mypy-posthog.test.*]
20+
ignore_errors = True
21+
22+
[mypy-posthog.*.test.*]
23+
ignore_errors = True
24+
25+
[mypy-openai.*]
26+
ignore_missing_imports = True
27+
28+
[mypy-langchain.*]
29+
ignore_missing_imports = True
30+
31+
[mypy-langchain_core.*]
32+
ignore_missing_imports = True
33+
34+
[mypy-anthropic.*]
35+
ignore_missing_imports = True
36+
37+
[mypy-httpx.*]
38+
ignore_missing_imports = True

posthog/exception_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def event_from_exception(
793793

794794

795795
def _module_in_list(name, items):
796-
# type: (str, Optional[List[str]]) -> bool
796+
# type: (str | None, Optional[List[str]]) -> bool
797797
if name is None:
798798
return False
799799

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@
2525
extras_require = {
2626
"dev": [
2727
"black",
28+
"django-stubs",
2829
"isort",
2930
"flake8",
3031
"flake8-print",
32+
"lxml",
33+
"mypy",
34+
"mypy-baseline",
35+
"types-mock",
36+
"types-python-dateutil",
37+
"types-requests",
38+
"types-setuptools",
39+
"types-six",
3140
"pre-commit",
41+
"pydantic",
3242
],
3343
"test": [
3444
"mock>=2.0.0",

0 commit comments

Comments
 (0)