Skip to content

Commit

Permalink
Removes unnecessary quotes after flake8-type-checking upgrade
Browse files Browse the repository at this point in the history
Fixes lint workflow
  • Loading branch information
Daverball authored May 29, 2024
1 parent e483f25 commit cb2febf
Show file tree
Hide file tree
Showing 130 changed files with 243 additions and 231 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,20 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[mypy] GitPython flake8 flake8-bugbear flake8-pyi bandit[toml]
python -m pip install --upgrade uv
uv pip install .[mypy] \
GitPython \
flake8 \
flake8-broken-line \
flake8-bugbear \
flake8-comprehensions \
flake8-markupsafe@git+https://github.com/vmagamedov/flake8-markupsafe#egg=b391bd13df9330e01666d304b7f4403d67e5ceba \
flake8-noqa \
flake8-pyi \
flake8-type-checking \
bandit[toml]
env:
UV_SYSTEM_PYTHON: true

- name: Linting
run: flake8 src/ tests/ stubs/
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- 'flake8-markupsafe@git+https://github.com/vmagamedov/flake8-markupsafe#egg=b391bd13df9330e01666d304b7f4403d67e5ceba'
- flake8-noqa
- flake8-pyi
- flake8-type-checking>=2.5.1
- flake8-type-checking>=2.9.1
- repo: https://github.com/elidupuis/mirrors-sass-lint
rev: '5cc45653263b423398e4af2561fae362903dd45d'
hooks:
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/agency/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PersonLayout(OrgPersonLayout):
@cached_property
def editbar_links(self) -> list[Link | LinkGroup] | None:
if self.has_model_permission(Private):
traits: 'Sequence[Trait]'
traits: Sequence[Trait]
if not self.model.deletable(self.request):
traits = (
Block(
Expand Down Expand Up @@ -205,7 +205,7 @@ def breadcrumbs(self) -> list[Link]:
def editbar_links(self) -> list[Link | LinkGroup] | None:
if self.has_model_permission(Private):
if self.model.deletable(self.request):
delete_traits: 'Sequence[Trait]' = (
delete_traits: Sequence[Trait] = (
Confirm(
_("Do you really want to delete this agency?"),
_("This cannot be undone."),
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/agency/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def emails_for_new_ticket(
that need to be notified for a new ticket of this type
"""

agencies: 'Iterable[Agency]'
agencies: Iterable[Agency]
if isinstance(model, Agency):
agencies = (model, )
handler_code = 'AGN'
Expand Down Expand Up @@ -66,7 +66,7 @@ def emails_for_new_ticket(

# we try to minimize the amount of e-mail address parsing we
# perform by de-duplicating the raw usernames as we get them
role_mapping: 'RoleMapping'
role_mapping: RoleMapping
for agency in agencies:
for role_mapping in getattr(agency, 'role_mappings', ()):
if role_mapping.role != 'editor':
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def session(self) -> 'Session':
def links(self) -> dict[str, 'Self | None']:
""" Returns a dictionary with pagination instances. """

result: dict[str, 'Self | None'] = {'prev': None, 'next': None}
result: dict[str, Self | None] = {'prev': None, 'next': None}

previous = self.collection.previous
if previous:
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/ballot/models/election/candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def percentage_by_entity(self) -> dict[int, 'EntityPercentage']:
CandidateResult.votes.label('votes')
)

percentage: dict[int, 'EntityPercentage'] = {
percentage: dict[int, EntityPercentage] = {
r.id: {
'counted': r.counted,
'votes': r.votes,
Expand Down Expand Up @@ -259,7 +259,7 @@ def percentage_by_district(self) -> dict[str, 'DistrictPercentage']:
results = results.group_by(ElectionResult.district)
results = results.order_by(None)

percentage: dict[str, 'DistrictPercentage'] = {
percentage: dict[str, DistrictPercentage] = {
r.name: {
'counted': r.counted,
'entities': r.entities,
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/ballot/models/election/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def percentage_by_entity(self) -> dict[int, 'EntityPercentage']:
totals_by_entity.c.entity_id == results_sub.c.id
)

percentage: dict[int, 'EntityPercentage'] = {
percentage: dict[int, EntityPercentage] = {
r.id: {
'counted': r.counted,
'votes': r.votes,
Expand Down Expand Up @@ -233,7 +233,7 @@ def percentage_by_district(self) -> dict[str, 'DistrictPercentage']:
totals_by_district.c.district == results_sub.c.name
)

percentage: dict[str, 'DistrictPercentage'] = {
percentage: dict[str, DistrictPercentage] = {
r.name: {
'counted': r.counted,
'entities': r.entities,
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def sendmail(group_context: 'GroupContext', queue: str, limit: int) -> None:
click.echo('No directory configured for this queue.', err=True)
sys.exit(1)

qp: 'MailQueueProcessor'
qp: MailQueueProcessor
if mailer == 'postmark':
qp = PostmarkMailQueueProcessor(cfg['token'], directory, limit=limit)
qp.send_messages()
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/cli/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def process_results(
if not processor:
return

processors: 'Sequence[Callable[..., Any]]'
processors: Sequence[Callable[..., Any]]
if callable(processor):
processors = (processor, )
else:
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/core/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def convert_xlsx_to_csv(
except Exception as exception:
raise IOError("Could not read XLSX file") from exception

sheet: 'Worksheet'
sheet: Worksheet
if sheet_name:
try:
sheet = excel[sheet_name]
Expand Down Expand Up @@ -526,7 +526,7 @@ def get_keys_from_list_of_dicts(
the reverse flag is ignored.
"""
fields_set: 'OrderedSet[str]' = OrderedSet()
fields_set: OrderedSet[str] = OrderedSet()

for dictionary in rows:
fields_set.update(dictionary.keys())
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class TemplateVariablesRegistry:
__slots__ = ('callbacks',)

def __init__(self) -> None:
self.callbacks: list['Callable[[CoreRequest], dict[str, Any]]'] = []
self.callbacks: list[Callable[[CoreRequest], dict[str, Any]]] = []

def get_variables(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __call__(
def __call__(self) -> 'WSGIApplication': # noqa:F811
""" Intercept all wsgi calls so we can attach debug tools. """

fn: 'WSGIApplication' = super().__call__
fn: WSGIApplication = super().__call__
fn = self.with_print_exceptions(fn)
fn = self.with_request_cache(fn)

Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def html_to_text(
for key, value in config.items():
setattr(html2text, key, value)

lines: 'Iterable[str]' = html2text.handle(html).splitlines()
lines: Iterable[str] = html2text.handle(html).splitlines()

# ignore images doesn't catch all images:
if ignore_images:
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def prepare_email(
# this leads to a lower spam rating
plaintext = html_to_text(content)

message: 'EmailJsonDict' = {
message: EmailJsonDict = {
'From': format_single_address(sender),
'To': format_address(receivers),
'TextBody': plaintext,
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/orm/mixins/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def wrapper(fn: 'Callable[[Any], ColumnElement[_T]]') -> Any:

def _expr(self, owner: type[Any]) -> 'QueryableAttribute | None':
if self.custom_getter is None:
column: 'Column[dict[str, Any]]' = getattr(owner, self.attribute)
column: Column[dict[str, Any]] = getattr(owner, self.attribute)
expr = column[self.key]
if self.value_type is None:
pass
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/core/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def __init__(self, request: 'CoreRequest'):
#
conn = session._connection_for_bind( # type:ignore[attr-defined]
session.bind)
self.operations_connection: 'Connection' = conn
self.operations_connection: Connection = conn
self.operations = Operations(
MigrationContext.configure(self.operations_connection))

Expand Down
6 changes: 3 additions & 3 deletions src/onegov/directory/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def write(
def write_directory_metadata(self, directory: Directory) -> None:
""" Writes the metadata. """

metadata: 'JSON_ro' = {
metadata: JSON_ro = {
'configuration': directory.configuration.to_dict(),
'structure': directory.structure.replace('\r\n', '\n'),
'title': directory.title,
Expand Down Expand Up @@ -448,7 +448,7 @@ def as_dict(entry: DirectoryEntry) -> dict[str, Any | None]:

return data

entries: 'Iterable[DirectoryEntry]'
entries: Iterable[DirectoryEntry]
entries = query.all() if query else directory.entries
if entry_filter:
entries = entry_filter(entries)
Expand Down Expand Up @@ -478,7 +478,7 @@ def write_paths(
A dictionary with the mapping of the file id to the entry name
"""

files: 'Iterable[File]'
files: Iterable[File]
if paths:
files = session.query(File).filter(File.id.in_(paths))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/collections/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def trigger_summarized(
"""

model_chain: 'Iterator[Election|ElectionCompound|Vote]'
model_chain: Iterator[Election | ElectionCompound | Vote]
model_chain = chain(elections, election_compounds, votes)
models = tuple(model_chain)

Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def by_categories(
categories: 'Iterable[str]'
) -> dict[str, 'ScreenWidget']:

result: dict[str, 'ScreenWidget'] = {}
result: dict[str, ScreenWidget] = {}
for category in categories:
result.update(self.get(category, {}))
return result
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/formats/imports/election/ech.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def import_result_delivery(
election.absolute_majority = None
for candidate in candidates.values():
candidate.elected = False
elected_candidates: list['MajoralElected|ProportionalElected'] = []
elected_candidates: list[MajoralElected | ProportionalElected] = []

if result.elected:
if result.elected.majoral_election:
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/election_day/formats/imports/vote/wabstic.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def import_vote_wabstic(
return errors

# Get the vote type
used_ballot_types: list['BallotType'] = ['proposal']
used_ballot_types: list[BallotType] = ['proposal']
if vote.type == 'complex':
used_ballot_types.extend(['counter-proposal', 'tie-breaker'])

Expand Down Expand Up @@ -155,7 +155,7 @@ def import_vote_wabstic(
continue

# Parse the results
ballot_results: dict['BallotType', list[dict[str, Any]]]
ballot_results: dict[BallotType, list[dict[str, Any]]]
ballot_results = {key: [] for key in used_ballot_types}
added_entities = []
assert sg_gemeinden is not None
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/forms/election.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def on_request(self) -> None:

query = self.request.session.query(Election)
query = query.order_by(Election.date.desc(), Election.shortcode)
choices: list['_Choice'] = [
choices: list[_Choice] = [
(
election.id,
"{} {} {}".format(
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/election_day/forms/election_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def on_request(self) -> None:
ElectionCompound.date.desc(),
ElectionCompound.shortcode
)
choices: list['_Choice'] = [
choices: list[_Choice] = [
(
compound.id,
"{} {} {}".format(
Expand Down Expand Up @@ -599,7 +599,7 @@ def apply_model(self, model: ElectionCompound) -> None:
'lower_apportionment_pdf'
):
field = getattr(self, file_attr)
file: 'File' = getattr(model, file_attr)
file: File = getattr(model, file_attr)
if file:
field.data = {
'filename': file.reference.filename,
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/election_day/layouts/election.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def main_view(self) -> str:

@cached_property
def menu(self) -> 'NestedMenu':
result: 'NestedMenu' = []
result: NestedMenu = []

submenus = (
(_("Lists"), ('lists', 'list-by-entity', 'list-by-district',
Expand All @@ -256,7 +256,7 @@ def menu(self) -> 'NestedMenu':
)
for title, group in submenus:
if any(self.tab_visible(tab) for tab in group):
submenu: 'NestedMenu' = [
submenu: NestedMenu = [
(
self.subtitle(tab) or self.title(tab),
self.request.link(self.model, tab),
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/election_day/layouts/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def menu(self) -> 'NestedMenu':
session = self.request.session
principal = self.principal

result: 'NestedMenu' = []
result: NestedMenu = []
result.append((
_("Votes"),
self.request.link(VoteCollection(session)),
Expand All @@ -71,7 +71,7 @@ def menu(self) -> 'NestedMenu':
[]
))
else:
submenu: 'NestedMenu' = []
submenu: NestedMenu = []
submenu.append((
_("Elections"),
self.request.link(ElectionCollection(session)),
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/election_day/layouts/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ def answer(self) -> str | None:
@cached_property
def menu(self) -> 'NestedMenu':
if self.type == 'complex':
result: 'NestedMenu' = []
result: NestedMenu = []

for title, prefix in (
(_("Proposal"), 'proposal'),
(_("Counter Proposal"), 'counter-proposal'),
(_("Tie-Breaker"), 'tie-breaker')
):
submenu: 'NestedMenu' = [
submenu: NestedMenu = [
(
self.subtitle(tab),
self.request.link(self.model, tab),
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def email_iter() -> 'Iterator[EmailJsonDict]':
if subject:
subject_ = request.translate(subject)
else:
items: 'Iterator[Election | ElectionCompound | Vote]'
items: Iterator[Election | ElectionCompound | Vote]
items = chain(
group.election_compounds,
group.elections,
Expand Down
6 changes: 3 additions & 3 deletions src/onegov/election_day/models/principal.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def __init__(
}
has_superregions = superregions != {None}

domains_election: dict[str, 'TranslationString'] = OrderedDict()
domains_election: dict[str, TranslationString] = OrderedDict()
domains_election['federation'] = _("Federal")
domains_election['canton'] = _("Cantonal")
if has_regions:
Expand All @@ -313,7 +313,7 @@ def __init__(
)
domains_election['municipality'] = _("Communal")

domains_vote: dict[str, 'TranslationString'] = OrderedDict()
domains_vote: dict[str, TranslationString] = OrderedDict()
domains_vote['federation'] = _("Federal")
domains_vote['canton'] = _("Cantonal")
domains_vote['municipality'] = _("Communal")
Expand Down Expand Up @@ -394,7 +394,7 @@ def __init__(

kwargs.pop('segmented_notifications', None)

domains: dict[str, 'TranslationString'] = OrderedDict((
domains: dict[str, TranslationString] = OrderedDict((
('federation', _("Federal")),
('canton', _("Cantonal")),
('municipality', _("Communal"))
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/election_day/utils/archive_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_csv(self) -> None:
"""

votes = self.all_counted_votes_with_results()
entities: 'Iterable[tuple[str, Collection[Entity]]]' = [
entities: Iterable[tuple[str, Collection[Entity]]] = [
('votes', votes),
('elections', self.all_counted_election_with_results()),
('elections', self.all_counted_election_compounds_with_results())
Expand Down
Loading

0 comments on commit cb2febf

Please sign in to comment.