Skip to content
Merged
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
1 change: 0 additions & 1 deletion mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ posthog/request.py:0: note: (or run "mypy --install-types" to install all missin
posthog/request.py:0: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
posthog/request.py:0: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment]
posthog/consumer.py:0: error: Name "Empty" already defined (possibly by an import) [no-redef]
posthog/consumer.py:0: error: Need type annotation for "items" (hint: "items: list[<type>] = ...") [var-annotated]
posthog/consumer.py:0: error: Unsupported operand types for <= ("int" and "str") [operator]
posthog/consumer.py:0: note: Right operand is of type "int | str"
posthog/consumer.py:0: error: Unsupported operand types for < ("str" and "int") [operator]
Expand Down
3 changes: 2 additions & 1 deletion posthog/consumer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any
Comment thread
mishrak5j marked this conversation as resolved.
import json
import logging
import time
Expand Down Expand Up @@ -96,7 +97,7 @@ def upload(self):
def next(self):
"""Return the next batch of items to upload."""
queue = self.queue
items = []
items: list[Any] = []
Comment thread
mishrak5j marked this conversation as resolved.

start_time = time.monotonic()
total_size = 0
Expand Down
12 changes: 6 additions & 6 deletions posthog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from collections import defaultdict
from dataclasses import asdict, is_dataclass
from datetime import date, datetime, timezone
from datetime import date, datetime, timezone, timedelta
from decimal import Decimal
from typing import Any, Optional
from uuid import UUID
Expand All @@ -16,18 +16,18 @@
log = logging.getLogger("posthog")


def is_naive(dt):
def is_naive(dt: datetime) -> bool:
"""Determines if a given datetime.datetime is naive."""
return dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None # pragma: no mutate


def total_seconds(delta):
"""Determines total seconds with python < 2.7 compat."""
def total_seconds(delta: timedelta) -> float:
"""Return the total number of seconds contained in the duration."""
# http://stackoverflow.com/questions/3694835/python-2-6-5-divide-timedelta-with-timedelta
return (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 1e6) / 1e6


def guess_timezone(dt):
def guess_timezone(dt: datetime) -> datetime:
"""Attempts to convert a naive datetime to an aware datetime."""
if is_naive(dt):
# attempts to guess the datetime.datetime.now() local timezone
Expand All @@ -44,7 +44,7 @@ def guess_timezone(dt):
return dt


def remove_trailing_slash(host):
def remove_trailing_slash(host: str) -> str:
if host.endswith("/"):
return host[:-1]
return host
Expand Down
Loading