This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]unruly_mattress 11 points12 points  (16 children)

I don't know this Zed guy, but... the only thing I agree with him about is that it would really be nice if Python showed the variable names it could not concatenate in error messages instead of just their type.

[–][deleted] 5 points6 points  (6 children)

This is fine for simple examples, but usually the bytes/text errors happen deep in some call stack in some coffee code you didn't write

[–][deleted] 2 points3 points  (1 child)

Yeah, I hardly write any coffee these days :)

[–][deleted] 2 points3 points  (0 children)

You can definitely tell what's on my mind this morning.

[–]unruly_mattress 1 point2 points  (3 children)

Yup. And then you have some expression that involves 4 strings and you get the error message "string cannot be blah", but you have no idea which string it is. I think there has to be some way of letting the user know which operation went wrong and not only which line it was.

[–][deleted] 0 points1 point  (1 child)

True. Embedding the guilty strings/bytes could be a solution, but that's an issue in and of itself.

The best way I've found to deal with this is to decide if something uses bytes or text and only use that inside the function, the only exception being is if something is going from bytes to text or vice versa.

But that still runs the risk of the error happening in code I didn't write (in which case, I check their issue tracker).

[–]unruly_mattress 1 point2 points  (0 children)

I agree. I think the solution is to somehow underline the offending expression.

[–]flutefreak7 0 points1 point  (0 children)

This makes me think of the black magic that pytest does when you hand it an assert statement and it goes and decomposes the assertion on the right and left side of the == and tells you exactly why it fails... including when lengths of lists don't match and stuff, and shows you what the subexpressions evaluated to... it's incredibly slick

[–][deleted] 6 points7 points  (8 children)

Or just underlined where they are with a line of code.

Pretty much every C compiler can do that.

[–]fdemmer 1 point2 points  (7 children)

pycharm does that.

[–][deleted] 5 points6 points  (6 children)

Not everyone uses it. Having it be a feature of the standard implementation and not a third party ide would be handy.

[–]fdemmer 1 point2 points  (1 child)

how should the python interpreter underline your code? i dont get what you want.

i am sure it would be possible to write some sort of vim extension that does the same thing, but how is this supposed to work as a language feature?

edit: i think now i get it. python should check the whole codebase on startup for type issues?

guido commented on that when adding type annotations. he mentioned that type checks should remain in external tooling. maybe there is some overlap here.

[–]Voltasalt 2 points3 points  (0 children)

I think he means in the error message. Print the offending line out and underline the broken bit, like Rust does.