agronholm / agronholm/typeguard

Support for type checking any mock with spec

Đang mở
#121 10 bình luận 3 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
Python
Star
1.8k
Fork
146
Merge trung bình
8 ngày 12 giờ
Pull request đã merge (30 ngày)
1

Mô tả

While working on [TestSlide](https://testslide.readthedocs.io/) (a Python test framework from Facebook), @david-caro, @fabriziocucci and myself found an issue with typeguard integration.

In summary, typeguard checks for types recursively (eg: for `Union`, `Tuple` etc), which is a good thing. However, we got failures when one of these recursive checks hits a mock object.

TestSlide type validation functionality plays nicely with mocks, and can [detect and extract their templates](https://github.com/facebookincubator/TestSlide/blob/0b36ffdb40d471d9e945864647265f0033f2d521/testslide/lib.py#L18-L42) for use in type validation. But, if a mock has no template, no type validation happens ([just like typeguard](https://github.com/agronholm/typeguard/blob/4d5dc398cd67952b8cff6a8b0492076156a0bd7d/typeguard/__init__.py#L556)).

TestSlide's interface for this is [public and extensible](https://github.com/facebookincubator/TestSlide/blob/0b36ffdb40d471d9e945864647265f0033f2d521/testslide/strict_mock.py#L734-L741), so we can add supports for any mock object, including TestSlide's own [StrictMock](https://testslide.readthedocs.io/en/master/strict_mock/index.html).

I cut this [clowny PR](https://github.com/facebookincubator/TestSlide/pull/172) for TestSlide, to add the extra logic to deal with mocks, by patching `typeguard.check_type` and wrapping it, so we can move on temporarily.

@agronholm , I'm willing to cut a PR for typeguard to implement this public interface for dealing with mocks, what do you think? Once available at typeguard, we can drop it from TestSlide.

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.