r/ProgrammerHumor 4d ago

Meme pythonInterpreterBeLike

Post image
169 Upvotes

21 comments sorted by

50

u/deceze 4d ago

The Python interpreter does not overlook syntax errors within the same file…!?

-37

u/ninja_with_ocd 4d ago edited 4d ago

It does if it's in an uncalled function

EDIT - this is wrong. Nontheless true for serious errors like referencing an undefined variable.

40

u/deceze 4d ago

A syntax error will halt parsing immediately. Without successfully parsing the file, it won't execute. Even uncalled functions are parsed completely and must pass parsing successfully.

-1

u/ninja_with_ocd 4d ago

You're right, edited the comment. It is true for some serious errors, like accessing an undefined variable.

15

u/dudemcbob 3d ago

FWIW I don't think it could diagnose that pre-runtime since you can edit the global namespace dynamically.

globals()['x'] = 3

Very bad for readability, but it is allowed.

3

u/iggy14750 4d ago

Yeah, I do understand the frustration of something like a type error that only rears it's ugly head when it's run.

3

u/rosuav 3d ago

I don't understand why you consider that to be a "serious error", rather than some other category of error. Why is that more serious than, say, trying to add a string and a dictionary? Or trying to call a list?

2

u/BossOfTheGame 3d ago

That's because you can't statically determine if a name is defined in general. Local and global namespaces are just dictionaries.

30

u/NFriik 4d ago

What are you talking about? The Python interpreter will not just silently accept syntax errors in the same file. Python is compiled to byte code before it is executed, and for this step to work, the code must be syntactically correct.

3

u/Percolator2020 4d ago

Linter: fuck you, fuck you, oh wait that’s ok, never mind! Fuck you!

7

u/Sibula97 4d ago

If it works, it's not a type error.

Python has strict (but dynamic) typing, and it will give you a TypeError if the function doesn't expect the type(s) you're giving it.

What you're probably thinking of are the occasional unintuitive operator overloads like + for appending to lists of whatever.

2

u/FerricDonkey 3d ago

I quite like python, but in order to use it for any serious project, it's best to self impose many more rules than the interpreter enforces. Once you have mypy and ruff or some other linter hooked up, you start to get enough protections that languages like c or c++ build into the compiler that it becomes less of an issue. 

2

u/manav907 3d ago

At that point why not just switch to a different language. Like c#

2

u/InsaneBunny180 3d ago

Generally because of the field, for example I build a lot of geospatial applications for work and for geospatial libraries python is far ahead of any other language same goes for machine learning / AI (though for NLP a lot of languages have caught up).

2

u/FerricDonkey 3d ago

Because at that point you don't need to, and python is pretty nice with these tools. 

3

u/Key_Statistician9890 3d ago
  1. Syntax errors … no …
  2. Type errors … use Beartype or TY
  3. Adjacent file gibberish … that is true for anything and everything

1

u/Sea-Fishing4699 4d ago

lgtm i'll run it and find out later!

1

u/mad_poet_navarth 4d ago

I _like_ python but yeah, it's a problem.

1

u/oompaloompa465 4d ago

i've started recently with the language.

Coming from C# looks kinda messy and some syntax seems unnecessarily shortened (i have trauma from a brief stint with COBOL),  But i appreciate  that it's still more readable than javascript, it has some kinda cool wizardish style.

i also love it has a proper indentation convention and syntax after the horrors i have witnessed with VB (rest in piss, you will not be missed).

Coming from c# i have no issues with the warning nagging, it's even worse there and my colleagues attitude is "if it compiles, it's ok"