Skip to content

Commit

Permalink
fix: linting/mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
mgagliardo91 committed Dec 11, 2024
1 parent dd7923b commit 25b1fde
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 96 deletions.
6 changes: 3 additions & 3 deletions contxt/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LAST_WEEK = NOW - timedelta(days=7)

# FIXME
OPTIONAL_PROMPT_KWARGS = {
OPTIONAL_PROMPT_KWARGS: Any = {
"prompt": True,
"default": "<none>",
"callback": lambda ctx, param, value: value if value != "<none>" else None,
Expand All @@ -23,14 +23,14 @@ def warn(msg: str):


def print_table(
items: List[Any], keys: Optional[List[str]] = None, sort_by: Optional[str] = None, count: bool = True
items: Any, keys: Optional[List[str]] = None, sort_by: Optional[str] = None, count: bool = True
) -> None:
if keys:
items = pluck(keys=keys, items=items)
sort_by = sort_by if sort_by in keys else None
if items:
print(Serializer.to_table(items, sort_by=sort_by))
if count:
if count and isinstance(items, list):
print(f"Count: {len(items)}")


Expand Down
2 changes: 1 addition & 1 deletion contxt/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _log_response(self, response: Response, *args, **kwargs) -> None:
t = response.elapsed.total_seconds()
logger.debug(
f"Called {response.request.method} {response.url} with body" # type: ignore
f" {response.request.body} ({t} s)"
f" {response.request.body!r} ({t} s)"
)

def _process_response(self, response: Response) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion contxt/services/contxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_project(self, project_id) -> Project:
resp = self.get(f"stacks/{project_id}")
return Project.from_api(resp)

def get_services(self, project_id: int = None) -> List[Service]:
def get_services(self, project_id: int | None = None) -> List[Service]:
if project_id:
resp = self.get(f"stacks/{project_id}")
return [Service.from_api(rec) for rec in resp["Services"]]
Expand Down
8 changes: 5 additions & 3 deletions contxt/services/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def create_field(self, field: Field) -> Field:
def get_time_series_for_field(
self,
field: Field,
start_time: datetime = None,
start_time: datetime | None = None,
window: Window = Window.RAW,
end_time: Optional[datetime] = None,
per_page: int = 1000,
Expand All @@ -174,7 +174,7 @@ def get_time_series_for_field(
def get_time_series_for_fields(
self,
fields: List[Field],
start_time: datetime = None,
start_time: datetime | None = None,
window: Window = Window.RAW,
end_time: Optional[datetime] = None,
) -> List[FieldTimeSeries]:
Expand Down Expand Up @@ -443,7 +443,9 @@ def send_time_series(

return responses

def get_source_field_cursor(self, source_key: str, field_name: str = None) -> Optional[datetime]:
def get_source_field_cursor(
self, source_key: str, field_name: str | None = None
) -> Optional[datetime]:
"""Get the cursor for the given source and field"""

url = f"org/{self.org_id}/sources/{source_key}"
Expand Down
2 changes: 1 addition & 1 deletion contxt/utils/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _keys(obj):
return []

@staticmethod
def to_dict(obj: Any, cls_key: str = None, key_filter: Callable = None):
def to_dict(obj: Any, cls_key: str | None = None, key_filter: Callable | None = None):
"""Serializes `obj` to a `dict`. To use a custom format, overload
`obj.to_dict()`.
Expand Down
203 changes: 118 additions & 85 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ python-slugify = "^6.1.2"

[tool.poetry.dev-dependencies]
black = "^24"
flake8 = "^5"
flake8 = "^7.1.1"
isort = "^5"
mkdocs = "^1.4.2"
mkdocs-click = "^0.8.0"
mypy = "^0"
mypy = "^1.13.0"
poethepoet = "^0"
pre-commit = "^3"
pytest = "^7"
Expand Down Expand Up @@ -60,3 +60,6 @@ profile = "black"
[build-system]
requires = ["poetry-core>=1.0"]
build-backend = "poetry.core.masonry.api"

[mypy]
exclude = "/contxt/generated/"
Empty file added tests/__init__.py
Empty file.

0 comments on commit 25b1fde

Please sign in to comment.