Skip to content

Commit ebfecf6

Browse files
committed
types(backend): add TypedDict schemas; enable mypy in CI; type annotate basic analysis
1 parent 276697a commit ebfecf6

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ jobs:
5555
pip install pytest
5656
pytest -q
5757
58+
- name: Type-check backend (mypy)
59+
run: |
60+
pip install mypy
61+
mypy backend
62+
5863

backend/pdf_server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from flask_cors import CORS
1313
import logging
1414
from werkzeug.utils import secure_filename
15+
from backend.types import BasicAnalysis
1516
from bleach.sanitizer import Cleaner
1617
from backend.errors import register_error_handlers, ValidationError
1718

@@ -68,12 +69,12 @@ def _block_external_url_fetcher(url):
6869
}
6970
})
7071

71-
def perform_basic_analysis(df: pd.DataFrame) -> dict:
72+
def perform_basic_analysis(df: pd.DataFrame) -> BasicAnalysis:
7273
"""Выполняет базовый анализ данных DataFrame."""
7374
logger.debug(f"Starting basic analysis. DataFrame shape: {df.shape}")
7475
logger.debug(f"DataFrame columns: {df.columns.tolist()}")
7576

76-
analysis = {
77+
analysis: BasicAnalysis = {
7778
'numeric_columns': {},
7879
'string_columns': {}
7980
}

backend/types.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import TypedDict, Dict, List, Any
2+
3+
4+
class NumericStats(TypedDict):
5+
sum: float
6+
mean: float
7+
min: float
8+
max: float
9+
10+
11+
class StringStats(TypedDict):
12+
unique_values_count: int
13+
unique_values: List[str]
14+
15+
16+
class BasicAnalysis(TypedDict):
17+
numeric_columns: Dict[str, NumericStats]
18+
string_columns: Dict[str, StringStats]
19+
20+
21+
class FileUploadResponse(TypedDict):
22+
table_data: List[Dict[str, Any]]
23+
columns: List[str]
24+
total_rows: int
25+
current_page: int
26+
page_size: int
27+
total_pages: int
28+
basic_analysis: BasicAnalysis
29+
30+

mypy.ini

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[mypy]
2+
python_version = 3.12
3+
ignore_missing_imports = True
4+
warn_unused_ignores = True
5+
warn_redundant_casts = True
6+
warn_unused_configs = True
7+
strict_optional = True
8+
9+
[mypy-backend.*]
10+
disallow_untyped_defs = True
11+
check_untyped_defs = True
12+
13+

0 commit comments

Comments
 (0)