Skip to content

Commit

Permalink
fix: fix mypy errors on Python3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
hiro-o918 committed Sep 22, 2024
1 parent 916a630 commit a4d8512
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion luigi/configuration/cfg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def before_write(self, parser, section, option, value):
class LuigiConfigParser(BaseParser, ConfigParser):
NO_DEFAULT = object()
enabled = True
optionxform = str
optionxform = str # type: ignore
_instance = None
_config_paths = [
'/etc/luigi/client.cfg', # Deprecated old-style global luigi config
Expand Down
8 changes: 5 additions & 3 deletions luigi/configuration/toml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
#
import os.path
from configparser import ConfigParser
from typing import Any, Dict

try:
import toml
toml_enabled = True
except ImportError:
toml = False
toml_enabled = False

from .base_parser import BaseParser
from ..freezing import recursively_freeze


class LuigiTomlParser(BaseParser, ConfigParser):
NO_DEFAULT = object()
enabled = bool(toml)
data = dict()
enabled = bool(toml_enabled)
data: Dict[str, Any] = dict()
_instance = None
_config_paths = [
'/etc/luigi/luigi.toml',
Expand Down
6 changes: 3 additions & 3 deletions luigi/db_task_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def find_task_by_id(self, id, session=None):
return session.query(TaskRecord).get(id)


class TaskParameter(Base):
class TaskParameter(Base): # type: ignore
"""
Table to track luigi.Parameter()s of a Task.
"""
Expand All @@ -201,7 +201,7 @@ def __repr__(self):
return "TaskParameter(task_id=%d, name=%s, value=%s)" % (self.task_id, self.name, self.value)


class TaskEvent(Base):
class TaskEvent(Base): # type: ignore
"""
Table to track when a task is scheduled, starts, finishes, and fails.
"""
Expand All @@ -215,7 +215,7 @@ def __repr__(self):
return "TaskEvent(task_id=%s, event_name=%s, ts=%s" % (self.task_id, self.event_name, self.ts)


class TaskRecord(Base):
class TaskRecord(Base): # type: ignore
"""
Base table to track information about a luigi.Task.
Expand Down
2 changes: 1 addition & 1 deletion luigi/freezing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
from collections import Mapping # type: ignore
import operator
import functools

Expand Down
2 changes: 1 addition & 1 deletion luigi/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,4 +1603,4 @@ def normalize(self, x):
class OptionalPathParameter(OptionalParameter, PathParameter):
"""Class to parse optional path parameters."""

expected_type = (str, Path)
expected_type = (str, Path) # type: ignore
2 changes: 1 addition & 1 deletion luigi/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"disable_hard_timeout",
"disable_window",
]
RetryPolicy = collections.namedtuple("RetryPolicy", _retry_policy_fields)
RetryPolicy = collections.namedtuple("RetryPolicy", _retry_policy_fields) # type: ignore


def _get_empty_retry_policy():
Expand Down
5 changes: 3 additions & 2 deletions luigi/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import re
import copy
import functools
from typing import Any, Dict

import luigi

Expand Down Expand Up @@ -170,7 +171,7 @@ class MyTask(luigi.Task):
"""

_event_callbacks = {}
_event_callbacks: Dict[Any, Any] = {}

#: Priority of the task: the scheduler should favor available
#: tasks with higher priority values first.
Expand All @@ -180,7 +181,7 @@ class MyTask(luigi.Task):

#: Resources used by the task. Should be formatted like {"scp": 1} to indicate that the
#: task requires 1 unit of the scp resource.
resources = {}
resources: Dict[str, Any] = {}

#: Number of seconds after which to time out the run function.
#: No timeout if set to 0.
Expand Down
9 changes: 5 additions & 4 deletions luigi/task_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"""

import abc

import logging
from typing import Any, Dict, List

logger = logging.getLogger('luigi-interface')


Expand All @@ -46,9 +47,9 @@ class Register(abc.ABCMeta):
same object.
2. Keep track of all subclasses of :py:class:`Task` and expose them.
"""
__instance_cache = {}
_default_namespace_dict = {}
_reg = []
__instance_cache: Dict[str, Any] = {}
_default_namespace_dict: Dict[str, Any] = {}
_reg: List[Any] = []
AMBIGUOUS_CLASS = object() # Placeholder denoting an error
"""If this value is returned by :py:meth:`_get_reg` then there is an
ambiguous task name (two :py:class:`Task` have the same name). This denotes
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ deps =
dropbox: dropbox>=11.0.0
jsonschema
mypy
types-toml
types-python-dateutil
types-requests
passenv =
USER JAVA_HOME POSTGRES_USER DATAPROC_TEST_PROJECT_ID GCS_TEST_PROJECT_ID GCS_TEST_BUCKET GOOGLE_APPLICATION_CREDENTIALS TRAVIS_BUILD_ID TRAVIS TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT CI DROPBOX_APP_TOKEN DOCKERHUB_TOKEN GITHUB_ACTIONS OVERRIDE_SKIP_CI_TESTS
setenv =
Expand Down

0 comments on commit a4d8512

Please sign in to comment.