Re:Python’s “type hints” are a bit of a disappointment to me
by zmgsabst on Friday April 22, 2022 @03:53AM
(#31119284)
> this is not a limitation of the type system, but of a specific type checker (mypy), that will hopefully be fixed soon
> Sure, but that's just because the standard library (for now?) doesn't offer deserialization with runtime validation.
> it's just the tooling that is lagging a bit behind at the moment
So… the standard library has exactly the problem I articulated, and you’re violently agreeing while speaking down to me.
I think that reflects poorly on you.
Re:Python’s “type hints” are a bit of a disappointment to me
by ImprobableTruth on Friday April 22, 2022 @11:26AM
(#31122783)
Your initial statement was that the type system was a poor architectural choice because it doesn't support standard python idioms. To the best of my ability I've tried to communicate that there's an important difference between the type system and the standard library, that one can make it work and that the situation is not worse than most other typed languages.
If you think that's violently agreeing and talking down to you, then there must be some communication barrier that I don't know how to overcome.
Re:Python’s “type hints” are a bit of a disappointment to me
by toolslive on Friday April 22, 2022 @07:43AM
(#31120430)
> JSON = Union[....]
This does not define the type of a valid json object. (fe None is not a valid json object, neither is '')
Re:Python’s “type hints” are a bit of a disappointment to me
by ImprobableTruth on Friday April 22, 2022 @10:31AM
(#31122024)
A decade or so ago JSON was changed so that JSON text doesn't have to be an object, it can also be a value. 'null' (or say, '5') is therefore legal JSON.
Re:Python’s “type hints” are a bit of a disappointment to me
by toolslive on Friday April 22, 2022 @11:03AM
(#31122472)
you're right:
https://www.rfc-editor.org/rfc/rfc8259.txt
>In fact, you admit that even fixed JSON can be difficult without a 3rd party library.
Sure, but that's just because the standard library (for now?) doesn't offer deserialization with runtime validation. Java doesn't have that either, if you want to parse JSON you'll have to either roll your own or rely on a third party library.
Don't get me wrong, the situation isn't perfect, but especially if you use the 'right' tooling, you can in my experience already get a perfectly serviceable experience, which to me is indicative that the type system itself is fine and pythonic, it's just the tooling that is lagging a bit behind at the moment.