Skip to content

Commit

Permalink
Address mypy violations on Python 3.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
charettes committed Apr 13, 2024
1 parent 74909a0 commit 804380c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
6 changes: 4 additions & 2 deletions syzygy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
field_db_default_supported = django.VERSION >= (5,)

try:
from django.db.migrations.autodetector import OperationDependency
from django.db.migrations.autodetector import ( # type: ignore[attr-defined]
OperationDependency,
)

except ImportError:

class OperationDependency(
class OperationDependency( # type: ignore[no-redef]
namedtuple("OperationDependency", "app_label model_name field_name type")
):
class Type:
Expand Down
2 changes: 1 addition & 1 deletion syzygy/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
MIGRATION_STAGES_FALLBACK: MigrationStagesSetting


def _configure():
def _configure() -> None:
global MIGRATION_STAGES_OVERRIDE
global MIGRATION_STAGES_FALLBACK
MIGRATION_STAGES_OVERRIDE = getattr(settings, "MIGRATION_STAGES_OVERRIDE", {})
Expand Down
2 changes: 1 addition & 1 deletion syzygy/management/commands/makemigrations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core.management.commands import makemigrations # type: ignore
from django.core.management.commands import makemigrations

from syzygy.autodetector import MigrationAutodetector

Expand Down
2 changes: 1 addition & 1 deletion syzygy/management/commands/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.apps import apps
from django.core.management import CommandError
from django.core.management.commands import migrate # type: ignore
from django.core.management.commands import migrate
from django.db import connections
from django.db.migrations.exceptions import AmbiguityError
from django.db.migrations.executor import MigrationExecutor
Expand Down
14 changes: 7 additions & 7 deletions syzygy/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def describe(self):
if field_db_default_supported:
# XXX: This allows for a more descriptive migration_name_fragment
# to be associated with instances of AlterField.
operations.AlterField.migration_name_fragment = cached_property(
operations.AlterField.migration_name_fragment.fget
operations.AlterField.migration_name_fragment = cached_property( # type: ignore[assignment,method-assign]
operations.AlterField.migration_name_fragment.fget # type: ignore[attr-defined]
)
operations.AlterField.migration_name_fragment.name = "migration_name_fragment"
operations.AlterField.migration_name_fragment.name = "migration_name_fragment" # type: ignore[attr-defined]

def get_pre_remove_field_operation(model_name, name, field, **kwargs):
if field.db_default is not NOT_PROVIDED:
Expand All @@ -152,9 +152,9 @@ def get_pre_remove_field_operation(model_name, name, field, **kwargs):
return operation

# XXX: Shim kept for historical migrations generated before Django 5.
PreRemoveField = get_pre_remove_field_operation # noqa: F811
PreRemoveField = get_pre_remove_field_operation # type: ignore[assignment,misc] # noqa: F811
else:
get_pre_remove_field_operation = PreRemoveField
get_pre_remove_field_operation = PreRemoveField # type: ignore[assignment]


class AddField(operations.AddField):
Expand Down Expand Up @@ -215,7 +215,7 @@ def get_pre_add_field_operation(model_name, name, field, preserve_default=True):
return operation

# XXX: Shim kept for historical migrations generated before Django 5.
AddField = get_pre_add_field_operation # noqa: F811
AddField = get_pre_add_field_operation # type: ignore[assignment,misc] # noqa: F811
else:
get_pre_add_field_operation = AddField

Expand Down Expand Up @@ -297,7 +297,7 @@ def get_post_add_field_operation(model_name, name, field, preserve_default=True)
return operation

# XXX: Shim kept for historical migrations generated before Django 5.
PostAddField = get_post_add_field_operation # noqa: F811
PostAddField = get_post_add_field_operation # type: ignore[assignment,misc] # noqa: F811
else:
get_post_add_field_operation = PostAddField

Expand Down
20 changes: 11 additions & 9 deletions syzygy/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def partition_operations(
# If a pre-deploy operation is encountered after a post-deployment
# one attempt to re-order operation is allowed.
if all(
op.reduce(operation, app_label) is True for op in post_deploy_operations # type: ignore
op.reduce(operation, app_label) is True for op in post_deploy_operations
):
stage_operations[Stage.PRE_DEPLOY].append(operation)
continue
Expand Down Expand Up @@ -162,14 +162,16 @@ def get_pre_deploy_plan(plan: Plan) -> Plan:
if must_post_deploy_migration(migration, backward):
post_deploy_plan[migration.app_label, migration.name] = migration
else:
post_deploy_dep = post_deploy_plan and next(
(
post_deploy_plan[dependency]
for dependency in migration.dependencies
if dependency in post_deploy_plan
),
None,
)
post_deploy_dep = None
if post_deploy_plan:
post_deploy_dep = next(
(
post_deploy_plan[dependency]
for dependency in migration.dependencies
if dependency in post_deploy_plan
),
None,
)
if post_deploy_dep:
inferred = []
stage_defined = _get_defined_stage(migration) is not None
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ deps =
[testenv:mypy]
usedevelop = false
basepython = python3.8
commands = mypy -p syzygy --warn-redundant-casts
commands = mypy -p syzygy --warn-redundant-casts --warn-unused-ignores
deps =
mypy
django-stubs
Expand Down

0 comments on commit 804380c

Please sign in to comment.