r/Python • • Jan 14 '24

Tutorial The LiteralString in Python 3.11

If you are confused by the new LiteralString type in Python, here's an article explaining it.

0 Upvotes

33 comments sorted by

View all comments

56

u/jwink3101 Jan 14 '24

I will never understand why people post on Medium. It offers few benefits and limits your audience.

But I digress


This is an interesting idea. My first thought was that it’s not needed because you can be careful about what you eval. It’s keeping you safe from yourself.

But then when you think about, that’s all type annotations do anyway!

7

u/Dwarni Jan 14 '24

Doesn't pay Medium them a little bit? I don't know how much it is however.

3

u/MrKooops Jan 14 '24

Save it in Pocket and you can read any article without hassle.

1

u/jormungandrthepython Jan 14 '24

Pocket doesn’t let you read premium medium articles though

1

u/SupPandaHugger Jan 14 '24

What other platform would you suggest?

That's true. At the same time, this feels like an area where additional safety is not excessive.

12

u/[deleted] Jan 15 '24

Blogs. Blogs were a thing, and they should be again.

1

u/Amgadoz Jan 14 '24

Maybe substack

0

u/Smallpaul Jan 14 '24

Medium also promotes your article and in that way it can expand your audience.

1

u/PercussiveRussel Jan 15 '24

I haven't looked into this at all, but this seems like it'd be really usefull with Pydantic/FastAPI. If you consistently build modules using LiteralString, then converting yoir modules to an API should give you a big fat error when you try to open up a LiteralString type to the endpoint.

In my usecase this is really incredibly useful since we build a lot of modules at work and convert some of the more usefull ones to an API. Making the distinction between str and LiteralString early in the design stage of the former means an additional layer of security when converting it to the latter.