Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meta-test to ensure all .py files follow PEP 563 #1318

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 0 deletions cognite/client/_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from concurrent.futures import ThreadPoolExecutor

from cognite.client.utils._concurrency import ConcurrencySettings, MainThreadExecutor, TaskExecutor
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/data_classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from cognite.client.data_classes.annotations import (
Annotation,
AnnotationFilter,
Expand Down
1 change: 1 addition & 0 deletions cognite/client/data_classes/annotation_types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
2 changes: 2 additions & 0 deletions cognite/client/data_classes/data_modeling/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from cognite.client.data_classes import filters
from cognite.client.data_classes.data_modeling import aggregations, query
from cognite.client.data_classes.data_modeling.aggregations import AggregatedValue, Aggregation
Expand Down
6 changes: 0 additions & 6 deletions cognite/client/utils/_auxiliary.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""Utilities for Cognite API SDK

This module provides helper methods and different utilities for the Cognite API Python SDK.

This module is protected and should not be used by end-users.
"""
from __future__ import annotations

import functools
Expand Down
2 changes: 2 additions & 0 deletions cognite/client/utils/_graph.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import Dict, List, Set, Tuple


Expand Down
17 changes: 17 additions & 0 deletions tests/tests_unit/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,20 @@ def test_assert_no_root_init_file():
# or uses a pkgutil-style __init__.py. If any distribution does not, it will cause the namespace logic to
# fail and the other sub-packages will not be importable"
assert not Path("cognite/__init__.py").exists()


def test_ensure_all_files_use_future_annots():
def keep(path):
skip_list = [
"_pb2.py", # Auto-generated, dislikes changes ;)
"cognite/client/utils/_priority_tpe.py", # Module docstring at the top takes priority
]
return all(skip not in str(path) for skip in skip_list)

all_filepaths = [Path(p) for p in Path("cognite/client/").glob("**/*.py") if keep(p)]
err_msg = "File: '{}' is missing 'from __future__ import annotations' at line=0"

for filepath in all_filepaths:
with filepath.open("r") as file:
# We just read the first line from each file:
assert file.readline() == "from __future__ import annotations\n", err_msg.format(filepath)
Loading