Skip to content

Commit

Permalink
Run Mypy as a local hook as it's unreliable if isolated without all deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Jan 7, 2024
1 parent 7d98aee commit a761f96
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 39 deletions.
36 changes: 13 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ci:
'no-commit-to-branch',
# 'hadolint-docker',
'docker-compose-check',
'mypy', # Runs as a local hook now
]
repos:
- repo: https://github.com/pre-commit-ci/pre-commit-ci-config
Expand Down Expand Up @@ -100,29 +101,6 @@ repos:
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
# warn-unused-ignores is unsafe with pre-commit, see
# https://github.com/python/mypy/issues/2960
args:
[
'--no-warn-unused-ignores',
'--no-warn-redundant-casts',
'--ignore-missing-imports',
]
additional_dependencies:
- flask
- lxml-stubs
- sqlalchemy
- toml
- types-chevron
- types-geoip2
- types-python-dateutil
- types-pytz
- types-requests
- typing-extensions
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
Expand Down Expand Up @@ -223,3 +201,15 @@ repos:
rev: v3.0.1
hooks:
- id: docker-compose-check
- repo: local
hooks:
- id: mypy
name: mypy
entry: .venv/bin/mypy
args:
- --no-warn-unused-ignores
- --no-warn-redundant-casts
- . # Required to honour settings in pyproject.toml
language: system
pass_filenames: false
types_or: [python, pyi]
6 changes: 4 additions & 2 deletions funnel/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import itertools
from collections.abc import Iterable, Iterator, Sequence
from datetime import datetime
from typing import TYPE_CHECKING, ClassVar, Literal, Self, cast, overload
from typing import TYPE_CHECKING, ClassVar, Literal, Self, TypeAlias, cast, overload
from uuid import UUID

import phonenumbers
Expand Down Expand Up @@ -2776,7 +2776,9 @@ def get(
)

#: Anchor type
Anchor = AccountEmail | AccountEmailClaim | AccountPhone | EmailAddress | PhoneNumber
Anchor: TypeAlias = (
AccountEmail | AccountEmailClaim | AccountPhone | EmailAddress | PhoneNumber
)

# Tail imports
from .account_membership import AccountMembership
Expand Down
2 changes: 1 addition & 1 deletion funnel/models/auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def all_for(cls, account: Account | None) -> Query[Self]:
return cls.query.order_by(cls.title)
return cls.query.filter(
sa.or_(
cls.account == account, # type: ignore[arg-type]
cls.account == account,
cls.account_id.in_(account.organizations_as_owner_ids()),
)
).order_by(cls.title)
Expand Down
2 changes: 1 addition & 1 deletion funnel/models/contact_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def grouped_counts_for(
).filter(
cls.ticket_participant_id == TicketParticipant.id,
TicketParticipant.project_id == Project.id,
cls.account == account, # type: ignore[arg-type]
cls.account == account,
)

if not archived:
Expand Down
5 changes: 1 addition & 4 deletions funnel/models/email_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,7 @@ def _validate_email(
if old_value == value:
# Old value is new value. Do nothing. Return without validating
return
if (
old_value is NO_VALUE
and inspect(target).has_identity is False # type: ignore[attr-defined]
):
if old_value is NO_VALUE and inspect(target).has_identity is False:
# Old value is unknown and target is a transient object. Continue
pass
elif value is None:
Expand Down
2 changes: 1 addition & 1 deletion funnel/models/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def icon(self) -> str:
result = ''.join(w[0] for w in self.title.strip().title().split(None, 2))
if len(result) <= 1:
result = self.title.strip()[:3]
return result # type: ignore[return-value]
return result

def __repr__(self) -> str:
"""Represent :class:`Label` as a string."""
Expand Down
1 change: 0 additions & 1 deletion funnel/models/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ def dispatch(self) -> Generator[NotificationRecipient, None, None]:
Subclasses wanting more control over how their notifications are dispatched
should override this method.
"""

for account, role in self.role_provider_obj.actors_with(
self.roles, with_role=True
):
Expand Down
5 changes: 1 addition & 4 deletions funnel/models/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,7 @@ def _validate_number(
if old_value == value:
# Old value is new value. Do nothing. Return without validating
return value
if (
old_value is NO_VALUE
and inspect(target).has_identity is False # type: ignore[attr-defined]
):
if old_value is NO_VALUE and inspect(target).has_identity is False:
# Old value is unknown and target is a transient object. Continue
pass
elif value is None:
Expand Down
2 changes: 1 addition & 1 deletion funnel/models/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def publish(self, actor: Account) -> bool:
if self.number is None:
self.number = (
sa.select(sa.func.coalesce(sa.func.max(Update.number), 0) + 1)
.where(Update.project == self.project) # type: ignore[arg-type]
.where(Update.project == self.project)
.scalar_subquery()
)
return first_publishing
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/models/proposal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_reorder(db_session, user_twoflower, project_expo2010) -> None:
assert proposal3.url_id == 3

assert proposal1.title == "Test Proposal 1"
assert proposal1.url_id < proposal2.url_id < proposal3.url_id # type: ignore[operator]
assert proposal1.url_id < proposal2.url_id < proposal3.url_id

proposal1.reorder_after(proposal2)
db_session.commit()
Expand Down

0 comments on commit a761f96

Please sign in to comment.