-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing a "Resources" or "More examples" section/page #160
Comments
Hi 👋 I'm happy that you're trying out phantom-types! I definitely think a resource/more examples/recipes section would be a good idea. I think the Sized collections section in the docs would also be improved with a few more examples. I've been meaning to put together a blog post about phantom types and I know @sobolevn have too, for me I just haven't been able to find the time ... yet. As to why you're example is failing, there are two problems in the code. Since the collection you are passing to a_list = [1, 2]
parsed = NonEmpty[int].parse(a_list)
a_list.clear() # the list is now empty
reveal_type(a_list) # but mypy would reveal NonEmpty So mutable collections are checked for and refused by the sized collection types. The Sized collections section in the docs and this recently added section about mutability mentions this. There is an open issue to change the behavior of The other problem in your code is Putting it all together, your example would become: from typing import List
from python.sized import NonEmpty
it_works = NonEmpty[str].parse("hello")
and_this_too = NonEmpty[int].parse((1, 2)) |
I haven't released it yet 😢 |
Thank you for such a detailed explanation 🙏🏼 😊 I'm eager to try #110 once it's out. Yet I found the syntax less intuitive to use (closer to Haskell's As for the resources & examples, I can work on that if that's okay. |
@espetro Cool! I just think it's nice that there are multiple things happening in this space within Python. Just a note on the I'll dig deeper into your library for inspiration! 👍 |
@espetro I presented phantom-types to typing-sig, the group that brings forth most of the typing features that makes it into Python. There's a recorded presentation with slides, that I mention here: #178 I was very nervous giving the talk, so I haven't watched it myself yet 🙈 But thought it might help in approaching this library. |
@antonagestam it was a great intro! 👏 |
@antonagestam I'm watching it right now, great talk by the way! 🚀 |
I've published a blog post about phantom types today, it doesn't go that much into detail about what you can do with the library though, and is deliberately more a raison d'être for phantom types in general. Please let me know if you have any feedback, small or big! 🙂 |
Hello! I'm willing to try this library with some dummy code I have with Pydantic and other serialization/validation libraries. However, I cannot get pass the example of using
str
. For example, I don't get why the following happens:Is there any additional example with container types, or a recorded talk/workshop showing how this works? Thanks in advance!
The text was updated successfully, but these errors were encountered: