ruff
71b52b83 - [red-knot] Allow `type[]` to be subscripted (#13667)

Commit
1 year ago
[red-knot] Allow `type[]` to be subscripted (#13667) Fixed a TODO by adding another TODO. It's the red-knot way! ## Summary `builtins.type` can be subscripted at runtime on Python 3.9+, even though it has no `__class_getitem__` method and its metaclass (which is... itself) has no `__getitem__` method. The special case is [hardcoded directly into `PyObject_GetItem` in CPython](https://github.com/python/cpython/blob/744caa8ef42ab67c6aa20cd691e078721e72e22a/Objects/abstract.c#L181-L184). We just have to replicate the special case in our semantic model. This will fail at runtime on Python <3.9. However, there's a bunch of outstanding questions (detailed in the TODO comment I added) regarding how we deal with subscriptions of other generic types on lower Python versions. Since we want to avoid too many false positives for now, I haven't tried to address this; I've just made `type` subscriptable on all Python versions. ## Test Plan `cargo test -p red_knot_python_semantic --lib`
Author
Parents
Loading