Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion routemaster/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def serve(ctx, bind, debug, workers): # pragma: no cover
cron_thread.stop()


def _validate_config(app: App):
def _validate_config(app: App) -> None:
try:
validate_config(app, app.config)
except ValidationError as e:
Expand Down
2 changes: 1 addition & 1 deletion routemaster/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class FeedConfig(NamedTuple):

class Webhook(NamedTuple):
"""Configuration for webdook requests."""
match: Pattern
match: Pattern[str]
headers: Dict[str, str]


Expand Down
2 changes: 1 addition & 1 deletion routemaster/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _pre_warm_feeds(
label: str,
accessed_variables: Iterable[str],
logging_context,
):
) -> None:
for accessed_variable in accessed_variables:
parts = accessed_variable.split('.')

Expand Down
2 changes: 1 addition & 1 deletion routemaster/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_job(
# Bound when scheduling a specific job for a state
fn: LabelStateProcessor,
label_provider: LabelProvider,
):
) -> None:
"""Process a single instance of a single cron job."""

def _iter_labels_until_terminating(state_machine, state):
Expand Down
3 changes: 2 additions & 1 deletion routemaster/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from dataclasses import InitVar, dataclass

from routemaster.utils import get_path, template_url
from routemaster.config import StateMachine


def feeds_for_state_machine(state_machine) -> Dict[str, 'Feed']:
def feeds_for_state_machine(state_machine: StateMachine) -> Dict[str, 'Feed']:
"""Get a mapping of feed prefixes to unfetched feeds."""
return {
x.name: Feed(x.url, state_machine.name) # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion routemaster/logging/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Base class for logging plugins."""

import contextlib
from typing import Any


class BaseLogger:
"""Base class for logging plugins."""

def __init__(self, config, *args, **kwargs) -> None:
def __init__(self, config: Any, *args, **kwargs) -> None:
self.config = config

def init_flask(self, flask_app):
Expand Down
3 changes: 2 additions & 1 deletion routemaster/logging/plugins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Plugin loading and configuration."""
import importlib
from typing import List

from routemaster.config import Config, LoggingPluginConfig
from routemaster.logging.base import BaseLogger
Expand All @@ -9,7 +10,7 @@ class PluginConfigurationException(Exception):
"""Raised to signal an invalid plugin that was loaded."""


def register_loggers(config: Config):
def register_loggers(config: Config) -> List[BaseLogger]:
"""
Iterate through all plugins in the config file and instatiate them.
"""
Expand Down
2 changes: 1 addition & 1 deletion routemaster/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ACTIVE_MIDDLEWARES = []


def middleware(fn: WSGIMiddleware):
def middleware(fn: WSGIMiddleware) -> WSGIMiddleware:
"""Decorator: add `fn` to ACTIVE_MIDDLEWARES."""
ACTIVE_MIDDLEWARES.append(fn)
return fn
Expand Down
5 changes: 4 additions & 1 deletion routemaster/state_machine/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def process_action(
return True


def _calculate_idempotency_token(label: LabelRef, latest_history) -> str:
def _calculate_idempotency_token(
label: LabelRef,
latest_history: History,
) -> str:
"""
We want to make sure that an action is only performed once.

Expand Down
4 changes: 2 additions & 2 deletions routemaster/state_machine/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _process_transitions_for_metadata_update(
label: LabelRef,
state_machine: StateMachine,
state_pending_update: State,
):
) -> None:
with app.session.begin_nested():
lock_label(app, label)
current_state = get_current_state(app, label, state_machine)
Expand Down Expand Up @@ -219,7 +219,7 @@ def process_cron(
app: App,
state_machine: StateMachine,
state: State,
):
) -> None:
"""
Cron event entrypoint.
"""
Expand Down
4 changes: 2 additions & 2 deletions routemaster/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ValidationError(Exception):
pass


def validate_config(app: App, config: Config):
def validate_config(app: App, config: Config) -> None:
"""Validate that a given config satisfies invariants."""
for state_machine in config.state_machines.values():
_validate_state_machine(app, state_machine)


def _validate_state_machine(app: App, state_machine: StateMachine):
def _validate_state_machine(app: App, state_machine: StateMachine) -> None:
"""Validate that a given state machine is internally consistent."""
with app.new_session():
_validate_route_start_to_end(state_machine)
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exclude=tests,migrations
[mypy]
ignore_missing_imports=true
strict_optional=true
disallow_any_generics=true

@mthpower mthpower Apr 25, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is an example of what this would disallow? (the documentation isn't very clear on this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foo: List rather than foo: List[int]

disallow_incomplete_defs=true

[coverage:run]
branch=True
Expand Down