Skip to content

Commit c2db0df

Browse files
authored
More strict rules in mypy (#9705) (#9906)
Signed-off-by: Raymond Etornam <retornam@users.noreply.github.com>
1 parent 24a951e commit c2db0df

28 files changed

Lines changed: 156 additions & 158 deletions

File tree

airflow/cli/cli_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def command(*args, **kwargs):
5151
func = import_string(import_path)
5252
return func(*args, **kwargs)
5353

54-
command.__name__ = name # type: ignore
54+
command.__name__ = name
5555

5656
return command
5757

airflow/configuration.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def getsection(self, section: str) -> Optional[Dict[str, Union[str, int, float,
467467
if (section not in self._sections and section not in self.airflow_defaults._sections): # type: ignore
468468
return None
469469

470-
_section = copy.deepcopy(self.airflow_defaults._sections[section]) # type: ignore
470+
_section = copy.deepcopy(self.airflow_defaults._sections[section])
471471

472472
if section in self._sections: # type: ignore
473473
_section.update(copy.deepcopy(self._sections[section])) # type: ignore
@@ -481,7 +481,7 @@ def getsection(self, section: str) -> Optional[Dict[str, Union[str, int, float,
481481
key = key.lower()
482482
_section[key] = self._get_env_var_option(section, key)
483483

484-
for key, val in _section.items(): # type: ignore
484+
for key, val in _section.items():
485485
try:
486486
val = int(val)
487487
except ValueError:
@@ -499,13 +499,13 @@ def write(self, fp, space_around_delimiters=True):
499499
# This is based on the configparser.RawConfigParser.write method code to add support for
500500
# reading options from environment variables.
501501
if space_around_delimiters:
502-
d = " {} ".format(self._delimiters[0]) # type: ignore
502+
d = " {} ".format(self._delimiters[0])
503503
else:
504-
d = self._delimiters[0] # type: ignore
504+
d = self._delimiters[0]
505505
if self._defaults:
506-
self._write_section(fp, self.default_section, self._defaults.items(), d) # type: ignore
506+
self._write_section(fp, self.default_section, self._defaults.items(), d)
507507
for section in self._sections:
508-
self._write_section(fp, section, self.getsection(section).items(), d) # type: ignore
508+
self._write_section(fp, section, self.getsection(section).items(), d)
509509

510510
def as_dict(
511511
self, display_source=False, display_sensitive=False, raw=False,

airflow/models/baseoperator.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import warnings
2727
from abc import ABCMeta, abstractmethod
2828
from datetime import datetime, timedelta
29-
from typing import (
30-
Any, Callable, ClassVar, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, Type, Union, cast,
31-
)
29+
from typing import Any, Callable, ClassVar, Dict, FrozenSet, Iterable, List, Optional, Set, Tuple, Type, Union
3230

3331
import attr
3432
import jinja2
@@ -1168,7 +1166,7 @@ def _set_relatives(self,
11681166
task_list = [task_or_task_list] # type: ignore
11691167

11701168
task_list = [
1171-
t.operator if isinstance(t, XComArg) else t # type: ignore
1169+
t.operator if isinstance(t, XComArg) else t
11721170
for t in task_list
11731171
]
11741172

@@ -1381,8 +1379,8 @@ def chain(*tasks: Union[BaseOperator, List[BaseOperator]]):
13811379
raise TypeError(
13821380
'Chain not supported between instances of {up_type} and {down_type}'.format(
13831381
up_type=type(up_task), down_type=type(down_task)))
1384-
up_task_list = cast(List[BaseOperator], up_task)
1385-
down_task_list = cast(List[BaseOperator], down_task)
1382+
up_task_list = up_task
1383+
down_task_list = down_task
13861384
if len(up_task_list) != len(down_task_list):
13871385
raise AirflowException(
13881386
f'Chain not supported different length Iterable '

airflow/models/dagrun.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818
from datetime import datetime
19-
from typing import Any, List, Optional, Tuple, Union, cast
19+
from typing import Any, List, Optional, Tuple, Union
2020

2121
from sqlalchemy import (
2222
Boolean, Column, DateTime, Index, Integer, PickleType, String, UniqueConstraint, and_, func, or_,
@@ -266,8 +266,6 @@ def get_dag(self):
266266
def get_previous_dagrun(self, state: Optional[str] = None, session: Session = None) -> Optional['DagRun']:
267267
"""The previous DagRun, if there is one"""
268268

269-
session = cast(Session, session) # mypy
270-
271269
filters = [
272270
DagRun.dag_id == self.dag_id,
273271
DagRun.execution_date < self.execution_date,

airflow/models/taskinstance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,9 +1771,9 @@ def filter_for_tis(
17711771
for tik in tis])
17721772
return or_(*filter_for_tis)
17731773
if all(isinstance(t, TaskInstance) for t in tis):
1774-
filter_for_tis = ([and_(TI.dag_id == ti.dag_id, # type: ignore
1775-
TI.task_id == ti.task_id, # type: ignore
1776-
TI.execution_date == ti.execution_date) # type: ignore
1774+
filter_for_tis = ([and_(TI.dag_id == ti.dag_id,
1775+
TI.task_id == ti.task_id,
1776+
TI.execution_date == ti.execution_date)
17771777
for ti in tis])
17781778
return or_(*filter_for_tis)
17791779

airflow/plugins_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
import pkg_resources
3131

32-
from airflow import settings # type: ignore
33-
from airflow.utils.file import find_path_from_directory # type: ignore
32+
from airflow import settings
33+
from airflow.utils.file import find_path_from_directory
3434

3535
log = logging.getLogger(__name__)
3636

airflow/providers/apache/hive/transfers/mssql_to_hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def execute(self, context: Dict[str, str]):
119119
cursor.execute(self.sql)
120120
with NamedTemporaryFile("w") as tmp_file:
121121
csv_writer = csv.writer(tmp_file, delimiter=self.delimiter, encoding='utf-8')
122-
field_dict = OrderedDict() # type:ignore
122+
field_dict = OrderedDict()
123123
col_count = 0
124124
for field in cursor.description:
125125
col_count += 1

airflow/providers/apache/hive/transfers/mysql_to_hive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def execute(self, context: Dict[str, str]):
150150
quotechar=self.quotechar,
151151
escapechar=self.escapechar,
152152
encoding="utf-8")
153-
field_dict = OrderedDict() # type:ignore
153+
field_dict = OrderedDict()
154154
for field in cursor.description:
155155
field_dict[field[0]] = self.type_map(field[1])
156156
csv_writer.writerows(cursor)

airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ def create_new_pod_for_operator(self, labels, launcher) -> Tuple[State, k8s.V1Po
370370
# noinspection PyTypeChecker
371371
pod = append_to_pod(
372372
pod,
373-
self.pod_runtime_info_envs + # type: ignore
373+
self.pod_runtime_info_envs +
374374
self.ports + # type: ignore
375-
self.resources + # type: ignore
375+
self.resources +
376376
self.secrets + # type: ignore
377377
self.volumes + # type: ignore
378378
self.volume_mounts # type: ignore

airflow/providers/docker/operators/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def __get_tls_config(self):
327327
ca_cert=self.tls_ca_cert,
328328
client_cert=(self.tls_client_cert, self.tls_client_key),
329329
verify=True,
330-
ssl_version=self.tls_ssl_version, # type: ignore
330+
ssl_version=self.tls_ssl_version,
331331
assert_hostname=self.tls_hostname
332332
)
333333
self.docker_url = self.docker_url.replace('tcp://', 'https://')

0 commit comments

Comments
 (0)