Skip to content

Commit 094a987

Browse files
committed
Fix ty type-checking errors
Fix all errors reported by ty across the codebase.
1 parent 8070637 commit 094a987

30 files changed

Lines changed: 121 additions & 125 deletions

bugwarrior/collect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def _aggregate_issues(service: "Service", queue: multiprocessing.Queue):
6464
log.critical(f"Worker for [{target}] exited: {e}")
6565
queue.put((SERVICE_FINISHED_ERROR, target))
6666
except BaseException as e:
67-
if hasattr(e, 'request') and e.request:
67+
if (request := getattr(e, 'request', None)) is not None:
6868
# Exceptions raised by requests library have the HTTP request
6969
# object stored as attribute. The request can have hooks attached
7070
# to it, and we need to remove them, as there can be unpickleable
7171
# methods. There is no one left to call these hooks anyway.
72-
e.request.hooks = {}
72+
request.hooks = {}
7373
log.exception(f"Worker for [{target}] failed: {e}")
7474
queue.put((SERVICE_FINISHED_ERROR, target))
7575
else:

bugwarrior/command.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ def _try_load_config(
3838
# configuration file which just failed to load.
3939
logging.basicConfig()
4040

41-
exc_info = sys.exc_info()
4241
log.critical(
4342
"Could not load configuration. "
4443
"Maybe you have not created a configuration file.",
45-
exc_info=(exc_info[0], exc_info[1], None),
44+
exc_info=True,
4645
)
4746
sys.exit(1)
4847

@@ -75,8 +74,8 @@ class AliasedCli(click.Group):
7574
def list_commands(self, ctx):
7675
return ctx.command.commands.keys()
7776

78-
def get_command(self, ctx, name):
79-
return ctx.command.commands[name]
77+
def get_command(self, ctx, cmd_name):
78+
return ctx.command.commands[cmd_name]
8079

8180

8281
@click.command(cls=AliasedCli)

bugwarrior/config/ini2toml_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ def unquote_flavors(file_contents: str) -> str:
131131

132132
def activate(translator: Translator):
133133
profile = translator["bugwarriorrc"]
134-
profile.description = "Convert 'bugwarriorrc' files to 'bugwarrior.toml'"
134+
profile.help_text = "Convert 'bugwarriorrc' files to 'bugwarrior.toml'"
135135
profile.intermediate_processors.append(process_values)
136136
profile.post_processors.append(unquote_flavors)

bugwarrior/config/load.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
import logging
33
import os
44
from pathlib import Path
5+
import sys
56
from typing import Any
67

7-
try:
8-
import tomllib # python>=3.11
9-
except ImportError:
10-
import tomli as tomllib # backport
8+
if sys.version_info >= (3, 11):
9+
import tomllib
10+
else:
11+
import tomli as tomllib # type: ignore[unresolved-import]
1112

1213
from .validation import Config, validate_config
1314

@@ -28,7 +29,7 @@ def configure_logging(logfile, loglevel):
2829
'requests.packages.urllib3.connectionpool',
2930
]
3031
for spammer in spammers:
31-
logging.getLogger(spammer).setLevel(logging.WARN)
32+
logging.getLogger(spammer).setLevel(logging.WARNING)
3233

3334

3435
def get_config_path():
@@ -134,10 +135,10 @@ def __init__(self, *args, allow_no_value=True, **kwargs):
134135
*args, allow_no_value=allow_no_value, interpolation=None, **kwargs
135136
)
136137

137-
def getint(self, section, option):
138+
def getint(self, section, option, **kwargs):
138139
"""Accepts both integers and empty values."""
139140
try:
140-
return super().getint(section, option)
141+
return super().getint(section, option, **kwargs)
141142
except ValueError:
142143
if self.get(section, option) == '':
143144
return None
@@ -148,7 +149,6 @@ def getint(self, section, option):
148149
)
149150
)
150151

151-
@staticmethod
152-
def optionxform(option):
152+
def optionxform(self, optionstr):
153153
"""Do not lowercase key names."""
154-
return option
154+
return optionstr

bugwarrior/config/schema.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
import re
55
import typing
6-
from typing import Annotated, Any, Generic, Literal
6+
from typing import Annotated, Literal
77

88
import pydantic
99
from pydantic import (
@@ -19,6 +19,7 @@
1919
)
2020
from pydantic_core import PydanticCustomError
2121
import taskw
22+
import taskw.task
2223

2324
from .data import BugwarriorData, get_data_path
2425

@@ -120,9 +121,7 @@ def _validate_unsupported(value: T) -> T:
120121
return value
121122

122123

123-
class UnsupportedOption(Generic[T]):
124-
def __class_getitem__(cls, item: type) -> Any:
125-
return Annotated[item, AfterValidator(_validate_unsupported)]
124+
UnsupportedOption = Annotated[T, AfterValidator(_validate_unsupported)]
126125

127126

128127
class BaseConfig(pydantic.BaseModel):
@@ -181,7 +180,7 @@ class Notifications(BaseConfig):
181180

182181

183182
# Dynamically add template fields to model.
184-
_ServiceConfig = pydantic.create_model(
183+
_ServiceConfig = pydantic.create_model( # type: ignore[no-matching-overload]
185184
"_ServiceConfig",
186185
__base__=BaseConfig,
187186
**{

bugwarrior/config/secrets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def oracle_eval(command):
7676
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
7777
)
7878
p.wait()
79+
assert p.stdout is not None
80+
assert p.stderr is not None
7981
if p.returncode == 0:
8082
return p.stdout.readline().strip().decode('utf-8')
8183
else:

bugwarrior/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def synchronize(issue_generator, conf: "Config", dry_run: bool = False):
302302
try:
303303
issue[key] = issue[key].decode('utf-8')
304304
except UnicodeDecodeError:
305-
log.warn("Failed to interpret %r as utf-8" % key)
305+
log.warning("Failed to interpret %r as utf-8" % key)
306306

307307
# Blank priority should mean *no* priority
308308
if issue['priority'] == '':

bugwarrior/docs/_ext/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class Config(SphinxDirective):
1111

1212
def _make_tab(self, lang: str):
1313
self.arguments = [lang]
14-
tab = TabDirective.run(self)[0]
15-
tab[1][0] = CodeBlock.run(self)[0]
14+
tab = TabDirective.run(self)[0] # type: ignore[arg-type]
15+
tab[1][0] = CodeBlock.run(self)[0] # type: ignore[arg-type]
1616
# While line breaks were previously separate elements, they're now
1717
# within the single CodeBlock element.
1818
del tab[1][1:]

bugwarrior/docs/_ext/extras.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import pathlib
2+
import sys
23

34
from docutils import nodes
45
from sphinx.util.docutils import SphinxDirective
56

6-
try:
7-
import tomllib # python>=3.11
8-
except ImportError:
9-
import tomli as tomllib # backport
7+
if sys.version_info >= (3, 11):
8+
import tomllib
9+
else:
10+
import tomli as tomllib # type: ignore[unresolved-import]
1011

1112

1213
class Extras(SphinxDirective):

bugwarrior/docs/generate_service_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from functools import reduce
1+
from functools import cmp_to_key, reduce
22
import inspect
33
import os
44
import sys
@@ -83,7 +83,7 @@ def row_comparator(left_row, right_row):
8383
]
8484
)
8585

86-
rows = sorted(rows, cmp=row_comparator)
86+
rows = sorted(rows, key=cmp_to_key(row_comparator))
8787
rows.insert(0, ['Field Name', 'Description', 'Type'])
8888

8989
filename = os.path.join(os.path.dirname(__file__), 'service_template.html')

0 commit comments

Comments
 (0)