Python Forum
When does Python detect Errors?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When does Python detect Errors?
#2
All python code is "executed" when the file is "compiled". First the source is converted into bytecodes, then the bytecodes are executed to define classes and functions and assign variables in the global scope. Syntax errors that result in not being able to parse the source code are caught in the conversion stage. Syntax errors like "this needs to be an expression" are caught in the second stage. Due to the dynamic nature of python, runtime errors like NameErrors, and AttributeErrors cannot be detected at this time. Python doesn't know what kind of object a function argument will be until the function gets called.

You can use a static analysis tool like mypy to catch a lot of the errors that would be caught by a traditional compiler. Consistently using type annotations helps with static analysis, and many IDE's can use the type information to identify potential problems and provide better code completion suggestions.

There is no substitute for testing. Python has great unit testing tools to help you detect runtime errors.
Reply


Messages In This Thread
When does Python detect Errors? - by stamp1t - Oct-21-2023, 04:56 PM
RE: When does Python detect Errors? - by deanhystad - Oct-21-2023, 05:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to detect abnormal data in big database python vanphuht91 5 1,208 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  Rmarkdown opened by python code - errors Rav013 0 2,133 Apr-27-2021, 03:13 PM
Last Post: Rav013
  Python Request Errors PythonNoob1998 7 4,187 Jan-07-2021, 05:18 PM
Last Post: buran
  Python chess game to detect winner ddddd 1 2,049 Dec-13-2020, 10:24 PM
Last Post: michael1789
  How to detect the text above lines using OpenCV in Python pframe 0 2,548 Apr-14-2020, 09:53 AM
Last Post: pframe
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 4,536 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Python stops without errors shahgourav 4 2,830 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Can the comments produce errors in python? newbieAuggie2019 9 4,434 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Detect finger clicks/snaps using Python fwinter102 0 2,072 Aug-12-2019, 04:02 PM
Last Post: fwinter102
  Running into errors when installing pip and pip3 on python 2.7 and python 3.6 tej7gandhi 1 2,890 May-05-2019, 10:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020