Skip to content

Commit de3bec3

Browse files
authored
Adds pass support (#299)
* Adds `pass` support, closes #284 * Fixes CI * Fixes CI
1 parent 090363a commit de3bec3

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

classes/contrib/mypy/validation/validate_typeclass_def.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from typing import Union
22

3-
from mypy.nodes import ARG_POS, EllipsisExpr, ExpressionStmt, FuncDef, StrExpr
3+
from mypy.nodes import (
4+
ARG_POS,
5+
EllipsisExpr,
6+
ExpressionStmt,
7+
FuncDef,
8+
PassStmt,
9+
StrExpr,
10+
)
411
from mypy.plugin import FunctionContext, MethodContext
512
from mypy.types import CallableType, Instance
613
from typing_extensions import Final
@@ -58,8 +65,10 @@ def _check_body(
5865
if body:
5966
is_useless_body = (
6067
len(body) == 1 and
61-
isinstance(body[0], ExpressionStmt) and
62-
isinstance(body[0].expr, (EllipsisExpr, StrExpr))
68+
(isinstance(body[0], PassStmt) or (
69+
isinstance(body[0], ExpressionStmt) and
70+
isinstance(body[0].expr, (EllipsisExpr, StrExpr))
71+
))
6372
)
6473
if is_useless_body:
6574
# We allow a single ellipsis in function a body.

typesafety/test_associated_type/test_validation/test_bodies.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@
2727
...
2828
out: |
2929
main:6: error: Associated types must not have bodies
30+
31+
32+
- case: associated_type_with_pass
33+
disable_cache: false
34+
main: |
35+
from classes import AssociatedType, typeclass
36+
37+
class MyType(AssociatedType):
38+
pass
39+
40+
@typeclass
41+
def sum_all(instance) -> int:
42+
pass

typesafety/test_typeclass/test_validation/test_body.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
main:3: error: Typeclass definitions must not have bodies
3131
3232
33+
- case: typeclass_with_pass_body
34+
disable_cache: false
35+
main: |
36+
from classes import typeclass
37+
38+
@typeclass
39+
def sum_all(instance) -> int:
40+
pass
41+
42+
3343
- case: typeclass_with_body_and_associated_type
3444
disable_cache: false
3545
main: |

0 commit comments

Comments
 (0)