laike9m / Python-Type-Challenges

Master Python typing (type hints) with interactive online exercises!
https://python-type-challenges.zeabur.app
MIT License
516 stars 32 forks source link

extreme-concatenate not working? (maybe outdated pyright) #82

Closed asottile closed 10 months ago

asottile commented 10 months ago

this works locally -- and on the version of pyright stated in requirements.txt

spoilers
```python from typing import Protocol class Person: pass class P1[R, **P](Protocol): def __call__(self, value: object, *args: P.args, **kwargs: P.kwargs) -> R: ... class P2[R, **P](Protocol): def __call__(self, value: Person, *args: P.args, **kwargs: P.kwargs) -> R: ... def transform[R, **P](f: P1[R, P]) -> P2[R, P]: def wrapper(value: Person, *args: P.args, **kwargs: P.kwargs) -> R: return f(value, *args, **kwargs) return wrapper ```

peeked at the stated solution and it feels a little cheeky to rely on the type checker to fill in the return value there

asottile commented 10 months ago

found out what's happening -- in the pyright playground it is not inferencing the reassignment of foo_with_person -- renaming the second one to foo_with_person2 fixes the puzzle output

no idea why it's different locally though

laike9m commented 10 months ago

I checked the playground with your code, it seems to work as expected?

image
asottile commented 10 months ago

very strange -- indeed appears to pass now \o/