antonagestam / phantom-types

Phantom types for Python.
https://pypi.org/project/phantom-types/
BSD 3-Clause "New" or "Revised" License
204 stars 9 forks source link

Add `TypeGuard` to `is_formatted_phone_number` #297

Closed flaeppe closed 2 months ago

flaeppe commented 4 months ago

I added an assert_type row since it seems that you are checking types with pytest-mypy-plugins but I figured using assert_type is probably preferable

antonagestam commented 4 months ago

Hmm, looks like something unrelated broke sized types badly, will look at it as soon as I have some time.

antonagestam commented 4 months ago

but I figured using assert_type is probably preferable

Yup, it didn't exist back then, much better 👍

This is probably a good idea, although the circular dependency between the type definition and its predicate bothers me just slightly. The TypeGuard function will also be an optimization over going through the isinstance interface though, so definitely seems like net positive.

antonagestam commented 2 months ago

Found minimal reproduction of the test failures, it's not related so I am merging this as is. Thanks for the contribution! 🙏

https://github.com/antonagestam/phantom-types/issues/299