Skip to content

Commit 566d794

Browse files
authored
Chore: update mypy to 1.2.0 (#411)
Fixed all new errors and warnings.
1 parent bfbc1f8 commit 566d794

File tree

14 files changed

+37
-31
lines changed

14 files changed

+37
-31
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ exclude =
9999
testing =
100100
ipfshttpclient==0.8.0a2 # eth/web3 test dependency, for some reason
101101
more-itertools==8.14.0
102-
mypy==0.950
102+
mypy==1.2.0
103103
pytest
104104
pytest-cov
105105
pytest-aiohttp

src/aleph/chains/chaindata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import json
3-
from typing import Dict, Optional, List, Any, Mapping, Set, cast
3+
from typing import Dict, Optional, List, Any, Mapping, Set, cast, Type, Union
44

55
from aleph_message.models import StoreContent, ItemType, Chain, MessageType
66
from pydantic import ValidationError
@@ -177,7 +177,7 @@ def _get_tx_messages_smart_contract_protocol(tx: ChainTxDb) -> List[Dict[str, An
177177
Message validation should be left to the message processing pipeline.
178178
"""
179179

180-
payload_model = (
180+
payload_model: Union[Type[TezosMessageEventPayload], Type[MessageEvent]] = (
181181
TezosMessageEventPayload if tx.chain == Chain.TEZOS else MessageEvent
182182
)
183183

src/aleph/chains/ethereum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def get_contract(config, web3: Web3):
6363

6464
def get_logs_query(web3: Web3, contract, start_height, end_height):
6565
return web3.eth.get_logs(
66-
{"address": contract.address, "fromBlock": start_height, "toBlock": end_height} # type: ignore[arg-type]
66+
{"address": contract.address, "fromBlock": start_height, "toBlock": end_height}
6767
)
6868

6969

src/aleph/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def init_node_cache(config: Config) -> NodeCache:
6666
return node_cache
6767

6868

69-
async def main(args):
69+
async def main(args: List[str]) -> None:
7070
"""Main entry point allowing external calls
7171
7272
Args:
@@ -82,7 +82,7 @@ async def main(args):
8282
key_pair = generate_keypair(args.print_key)
8383
save_keys(key_pair, args.key_dir)
8484
if args.print_key:
85-
print(key_pair.private_key.impl.export_key().decode("utf-8"))
85+
print(key_pair.private_key.impl.export_key().decode("utf-8")) # type: ignore[attr-defined]
8686

8787
return
8888

src/aleph/schemas/api/messages.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime as dt
2-
from typing import Optional, Generic, TypeVar, Literal, List, Any, Union, Dict
2+
from typing import Optional, Generic, TypeVar, Literal, List, Any, Union, Dict, Mapping
33

44
from aleph_message.models import (
55
AggregateContent,
@@ -8,7 +8,7 @@
88
ForgetContent,
99
PostContent,
1010
ProgramContent,
11-
StoreContent,
11+
StoreContent, AlephMessage,
1212
)
1313
from aleph_message.models import MessageType, ItemType
1414
from pydantic import BaseModel
@@ -91,7 +91,7 @@ class StoreMessage(
9191
}
9292

9393

94-
def format_message(message: Any) -> BaseMessage:
94+
def format_message(message: Any) -> AlephMessage:
9595
message_cls = MESSAGE_CLS_DICT[message.type]
9696
return message_cls.from_orm(message)
9797

@@ -164,7 +164,7 @@ class ForgottenMessageStatus(BaseMessageStatus):
164164

165165
class RejectedMessageStatus(BaseMessageStatus):
166166
status: MessageStatus = MessageStatus.REJECTED
167-
message: Dict[str, Any]
167+
message: Mapping[str, Any]
168168
error_code: ErrorCode
169169
details: Any
170170

src/aleph/schemas/base_messages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import datetime as dt
66
from hashlib import sha256
7-
from typing import Optional, Generic, TypeVar
7+
from typing import Optional, Generic, TypeVar, Any, Mapping, cast
88

99
from aleph_message.models import BaseContent, Chain
1010
from aleph_message.models import MessageType, ItemType
@@ -62,7 +62,7 @@ def check_item_type(cls, values):
6262
return values
6363

6464
@validator("item_hash")
65-
def check_item_hash(cls, v, values):
65+
def check_item_hash(cls, v: Any, values: Mapping[str, Any]):
6666
"""
6767
For inline item types, check that the item hash is equal to
6868
the hash of the item content.
@@ -73,7 +73,7 @@ def check_item_hash(cls, v, values):
7373
raise ValueError("Could not determine item type")
7474

7575
if item_type == ItemType.inline:
76-
item_content: str = values.get("item_content")
76+
item_content = cast(Optional[str], values.get("item_content"))
7777
if item_content is None:
7878
raise ValueError("Could not find inline item content")
7979

src/aleph/web/controllers/accounts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from aiohttp import web
66
from aleph_message.models import MessageType
7-
from pydantic import ValidationError
7+
from pydantic import ValidationError, parse_obj_as
88

99
from aleph.db.accessors.balances import get_total_balance
1010
from aleph.db.accessors.files import (
@@ -15,7 +15,7 @@
1515
from aleph.schemas.api.accounts import (
1616
GetAccountBalanceResponse,
1717
GetAccountFilesResponse,
18-
GetAccountFilesQueryParams,
18+
GetAccountFilesQueryParams, GetAccountFilesResponseItem,
1919
)
2020
from aleph.types.db_session import DbSessionFactory
2121
from aleph.web.controllers.app_state_getters import get_session_factory_from_request
@@ -105,7 +105,7 @@ async def get_account_files(request: web.Request) -> web.Response:
105105
response = GetAccountFilesResponse(
106106
address=address,
107107
total_size=total_size,
108-
files=file_pins,
108+
files=parse_obj_as(List[GetAccountFilesResponseItem], file_pins),
109109
pagination_page=query_params.page,
110110
pagination_total=nb_files,
111111
pagination_per_page=query_params.pagination,

src/aleph/web/controllers/aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def split_str(cls, v):
2828
return v
2929

3030

31-
async def address_aggregate(request):
31+
async def address_aggregate(request: web.Request) -> web.Response:
3232
"""Returns the aggregate of an address.
3333
TODO: handle filter on a single key, or even subkey.
3434
"""

src/aleph/web/controllers/channels.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from aleph.db.accessors.messages import get_distinct_channels
77
from aleph.types.channel import Channel
8-
from aleph.types.db_session import DbSessionFactory, DbSession
8+
from aleph.types.db_session import DbSession
9+
from aleph.web.controllers.app_state_getters import get_session_factory_from_request
910

1011

1112
@cached(ttl=60 * 120, cache=SimpleMemoryCache, timeout=120)
@@ -14,13 +15,13 @@ async def get_channels(session: DbSession) -> List[Channel]:
1415
return list(channels)
1516

1617

17-
async def used_channels(request):
18+
async def used_channels(request: web.Request) -> web.Response:
1819
"""All used channels list
1920
2021
TODO: do we need pagination?
2122
"""
2223

23-
session_factory: DbSessionFactory = request.app["session_factory"]
24+
session_factory = get_session_factory_from_request(request)
2425

2526
with session_factory() as session:
2627
channels = await get_channels(session)

src/aleph/web/controllers/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
@aiohttp_jinja2.template("index.html")
17-
async def index(request) -> Dict:
17+
async def index(request: web.Request) -> Dict:
1818
"""Index of aleph."""
1919

2020
session_factory: DbSessionFactory = get_session_factory_from_request(request)
@@ -23,7 +23,7 @@ async def index(request) -> Dict:
2323
return asdict(await get_metrics(session=session, node_cache=node_cache))
2424

2525

26-
async def status_ws(request):
26+
async def status_ws(request: web.Request) -> web.WebSocketResponse:
2727
ws = web.WebSocketResponse()
2828
await ws.prepare(request)
2929

@@ -47,13 +47,13 @@ async def status_ws(request):
4747
await asyncio.sleep(2)
4848

4949

50-
async def metrics(request):
50+
async def metrics(request: web.Request) -> web.Response:
5151
"""Prometheus compatible metrics.
5252
5353
Naming convention:
5454
https://prometheus.io/docs/practices/naming/
5555
"""
56-
session_factory: DbSessionFactory = get_session_factory_from_request(request)
56+
session_factory = get_session_factory_from_request(request)
5757
node_cache = get_node_cache_from_request(request)
5858

5959
with session_factory() as session:
@@ -64,7 +64,7 @@ async def metrics(request):
6464
)
6565

6666

67-
async def metrics_json(request):
67+
async def metrics_json(request: web.Request) -> web.Response:
6868
"""JSON version of the Prometheus metrics."""
6969
session_factory: DbSessionFactory = get_session_factory_from_request(request)
7070
node_cache = get_node_cache_from_request(request)

0 commit comments

Comments
 (0)