facebook / facebook/TestSlide

Cannot type check with `from __future__ import annotations`

Đang mở
#329 0 bình luận 0 reaction 1 người được giao Được @williamlw999-fb nhận Xem trên GitHub
Ngôn ngữ chính
Python
Star
149
Fork
62
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

`from __future__ import annotations` turns type annotations into strings that can later be evaluated at runtime via `typing.get_type_hints` see [PEP 563](https://peps.python.org/pep-0563/). This is problematic because TestSlide uses the following pattern to find the expected type:
```
try:
argspec = inspect.getfullargspec(template)
except TypeError:
return
expected_type = argspec.annotations.get("return")
```
In this scenario, expected_type is a `string` when the expected type is `Type` (see `_validate_argument_type()` which only works if expected_type is a `Type`).

It seems like a potential solution is:
```
try:
hints = get_type_hints(template)
expected_type = hints.get("return")
except TypeError:
return
```
Will continue testing (I am on python 3.8.6).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.