crytic / crytic/slither

improving effectiveness of static typing

Open
#1,613 0 comments 0 reactions 0 assignees View on GitHub
meta
Dominant language
Python
Stars
6.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

As we increase type coverage it would be great to add something like the following to functions that **should** handle **all** types, effectively using mypy to alert when pattern matching isn't exhaustive. This will help catch issues earlier on when large changes are made e.g. to support a new solidity feature.
```
from typing import NoReturn

def assert_never(x: NoReturn) -> NoReturn:
assert False, "Unhandled type: {}".format(type(x).__name__)

IntOrStr = int | str

def handle(x: IntOrStr) -> None:
if isinstance(x, str):
print(f"Handled {x}")
else:
assert_never(x) # Error: "int" is incompatible with "NoReturn"
```

https://github.com/microsoft/pyright/issues/2569

Contributor guide

Open the contributing guide

Research direction

No file, test, or entry point is named. Start by locating Python functions that use type-based branching or pattern matching and review the linked Pyright issue for the intended exhaustive-checking behavior. Done means the relevant handlers use static typing to flag unhandled types, including when support for a new Solidity feature is added.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.