Add internal classes and add type hints + mypy.

This commit is contained in:
David Wobrock authored and David Wobrock committed 2022-12-26 16:26:24 +01:00
1 parent 847ac1241a
commit 2ee7dac3b3
88 files changed
+603 -340

No files matched your search

+11 -5
View File
@@ -1,9 +1,11 @@
from __future__ import annotations
import os
from importlib import import_module
def split_path(path):
decomposed_path = []
def split_path(path: str) -> list[str]:
decomposed_path: list[str] = []
while 1:
head, tail = os.path.split(path)
if head == path: # sentinel for absolute paths
@@ -21,20 +23,21 @@ def split_path(path):
return decomposed_path
def split_migration_path(migration_path):
def split_migration_path(migration_path: str) -> tuple[str, str]:
from django.db.migrations.loader import MIGRATIONS_MODULE_NAME
decomposed_path = split_path(migration_path)
for i, p in enumerate(decomposed_path):
if p == MIGRATIONS_MODULE_NAME:
return decomposed_path[i - 1], os.path.splitext(decomposed_path[i + 1])[0]
return "", ""
def clean_bytes_to_str(byte_input):
def clean_bytes_to_str(byte_input: bytes) -> str:
return byte_input.decode("utf-8").strip()
def get_migration_abspath(app_label, migration_name):
def get_migration_abspath(app_label: str, migration_name: str) -> str:
from django.db.migrations.loader import MigrationLoader
module_name, _ = MigrationLoader.migrations_module(app_label)
@@ -42,6 +45,9 @@ def get_migration_abspath(app_label, migration_name):
migration_module = import_module(migration_path)
migration_file = migration_module.__file__
if not migration_file:
raise ValueError("Migration file not found")
if migration_file.endswith(".pyc"):
migration_file = migration_file[:-1]
return migration_file