Skip to content

Commit 18a008e

Browse files
committed
callable
1 parent cc08a54 commit 18a008e

18 files changed

Lines changed: 675 additions & 52 deletions

File tree

ROADMAP.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ upstream improvements. the symbol table phase handles nearly all near-term featu
4141

4242
## planned features
4343

44-
- [ ] language server (fork ty)
44+
- [ ] fork ruff/ty
45+
- essential features:
46+
- `lsp` subcommand (with full suite of features from ruff and ty)
47+
- `format` (from ruff)
48+
- `check` (from ruff)
49+
- `check` (from ty) - not sure about the name, maybe `lint` and `check` or maybe `typecheck`?
50+
- one option would be to produce two binaries: buff and by
4551
- [ ] source maps
4652
- [ ] build wheels (`by build`?)
4753
- ensure that built wheel depends on the correct deps for polyfill (`tomli`/`typing_extensions` etc)
@@ -60,7 +66,7 @@ upstream improvements. the symbol table phase handles nearly all near-term featu
6066
- [x] PEP 695 generics polyfill: `class A[T]`, `def f[T]()`, `type X = ...` → 3.10-compatible equivalents including TypeVar name renaming
6167
- [x] `typing` import redirect: names unavailable in stdlib until later versions are redirected to `typing_extensions`
6268
- [x] expression compat rewrites: `datetime.UTC`, `sys.exception()`, `math.exp2()` → 3.10-compatible equivalents
63-
- [ ] callable syntax: `(int) -> int` -> `Callable[[int], int]` / `[T](int, t: T) -> T` → a `Protocol` definition
69+
- [x] callable syntax: `(int) -> int` -> `Callable[[int], int]` / `[T](int, t: T) -> T` → a `Protocol` definition
6470
`(int, /, a: str, *args: int, **kwargs: str) -> None`
6571
- [x] unpack syntax in type annotations: `def f(*args: *tuple[int, ...])` -> `def f(*args: Unpack[tuple[int, ...]])` #easy
6672
- [x] intersection types: `A & B` -> `ty_extensions.Intersection[A, B]` #easy
@@ -84,6 +90,22 @@ upstream improvements. the symbol table phase handles nearly all near-term featu
8490
print(y)
8591
))
8692
```
93+
OR
94+
```bython
95+
x(: print(it))
96+
# trailing
97+
x: print(it)
98+
if x: print(it) # error, ambigious, need parens
99+
a = (): print(1)
100+
foo(:
101+
a = 1
102+
a + 1,
103+
:
104+
b = 2
105+
b + 1
106+
)
107+
```
108+
- [ ] annotations on `lambda`: `lambda (a: int, b: str) -> bool: a + b` -> `lambda a, b: a + b` #easy
87109
- [ ] extension functions: (needs design) `def Foo.bar():`
88110
- [ ] property syntax: (needs design)
89111
```
@@ -154,6 +176,16 @@ upstream improvements. the symbol table phase handles nearly all near-term featu
154176
- maybe also call expressions
155177
- [ ] make ternary expressions bearable: `if bool() 1 else 2`
156178
- [ ] `match`/`try` as an expression #easy
179+
- [ ] reified type parameters #harder
180+
```python
181+
def f[T](x: object) -> bool:
182+
return isinstance(x, T)
183+
```
184+
- [ ] generic function calls
185+
```python
186+
def f[T](t1: T, t2: T) -> T: ...
187+
f[object](1, "a")
188+
```
157189

158190
### anonymous named tuple:
159191
```

crates/ruff_python_ast/src/comparable.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,12 @@ pub struct ExprIpyEscapeCommand<'a> {
10081008
value: &'a str,
10091009
}
10101010

1011+
#[derive(Debug, PartialEq, Eq, Hash)]
1012+
pub struct ExprCallableType<'a> {
1013+
args: Vec<ComparableExpr<'a>>,
1014+
returns: Box<ComparableExpr<'a>>,
1015+
}
1016+
10111017
#[derive(Debug, PartialEq, Eq, Hash)]
10121018
pub enum ComparableExpr<'a> {
10131019
BoolOp(ExprBoolOp<'a>),
@@ -1045,6 +1051,7 @@ pub enum ComparableExpr<'a> {
10451051
Tuple(ExprTuple<'a>),
10461052
Slice(ExprSlice<'a>),
10471053
IpyEscapeCommand(ExprIpyEscapeCommand<'a>),
1054+
CallableType(ExprCallableType<'a>),
10481055
}
10491056

10501057
impl<'a> From<&'a Box<ast::Expr>> for Box<ComparableExpr<'a>> {
@@ -1324,6 +1331,15 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
13241331
range: _,
13251332
node_index: _,
13261333
}) => Self::IpyEscapeCommand(ExprIpyEscapeCommand { kind: *kind, value }),
1334+
ast::Expr::CallableType(ast::ExprCallableType {
1335+
args,
1336+
returns,
1337+
range: _,
1338+
node_index: _,
1339+
}) => Self::CallableType(ExprCallableType {
1340+
args: args.iter().map(ComparableExpr::from).collect(),
1341+
returns: Box::new(returns.as_ref().into()),
1342+
}),
13271343
}
13281344
}
13291345
}

0 commit comments

Comments
 (0)