Damien George
3c4bfd1dec
py/objexcept: Support errno attribute on OSError exceptions.
...
This commit adds the errno attribute to exceptions, so code can retrieve
errno codes from an OSError using exc.errno.
The implementation here simply lets `errno` (and the existing `value`)
attributes work on any exception instance (they both alias args[0]). This
is for efficiency and to keep code size down. The pros and cons of this
are:
Pros:
- more compatible with CPython, less difference to document and learn
- OSError().errno will correctly return None, whereas the current way of
doing it via OSError().args[0] will raise an IndexError
- it reduces code size on most bare-metal ports (because they already have
the errno qstr)
- for Python code that uses exc.errno the generated bytecode is 2 bytes
smaller and more efficient to execute (compared with exc.args[0]); so
bytecode loaded to RAM saves 2 bytes RAM for each use of this attribute,
and bytecode that is frozen saves 2 bytes flash/ROM for each use
- it's easier/shorter to type, and saves 2 bytes of space in .py files that
use it (for each use)
Cons:
- increases code size by 4-8 bytes on minimal ports that don't already have
the `errno` qstr
- all exceptions now have .errno and .value attributes (a cpydiff test is
added to address this)
See also #2407 .
Signed-off-by: Damien George <damien@micropython.org>
2021-04-23 22:03:46 +10:00
..
2020-04-05 15:02:06 +10:00
2020-06-27 00:24:04 +10:00
2020-06-27 00:24:04 +10:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2021-01-29 23:57:10 +11:00
2021-01-29 23:57:10 +11:00
2020-06-27 00:24:04 +10:00
2020-06-27 00:24:04 +10:00
2020-06-27 00:24:04 +10:00
2020-06-27 00:24:04 +10:00
2020-02-28 10:33:03 +11:00
2020-06-27 00:24:04 +10:00
2020-02-28 10:29:32 +11:00
2020-04-05 15:02:06 +10:00
2020-09-11 17:22:28 +10:00
2021-02-04 22:46:42 +11:00
2019-09-02 13:14:27 +10:00
2020-03-26 01:25:45 +11:00
2020-04-05 15:02:06 +10:00
2020-02-28 10:33:03 +11:00
2020-04-23 11:24:25 +10:00
2020-07-25 00:58:18 +10:00
2019-08-28 12:47:58 +10:00
2020-09-18 18:34:02 +10:00
2020-04-05 14:13:02 +10:00
2020-02-28 10:33:03 +11:00
2021-02-04 22:46:42 +11:00
2018-10-28 00:38:18 +11:00
2020-09-11 17:22:28 +10:00
2019-08-30 16:44:12 +10:00
2021-01-29 23:57:10 +11:00
2020-10-22 11:47:36 +02:00
2018-09-04 14:31:28 +10:00
2021-01-29 23:57:10 +11:00
2018-09-04 14:31:28 +10:00
2018-09-04 14:31:28 +10:00
2019-12-12 20:15:28 +11:00
2018-09-04 14:31:28 +10:00
2019-10-05 13:44:53 +10:00
2020-04-18 22:42:24 +10:00
2017-07-31 18:35:40 +10:00
2020-02-28 10:33:03 +11:00
2019-05-17 18:06:11 +10:00
2021-02-04 22:46:42 +11:00
2021-02-05 15:46:56 +11:00
2020-06-16 23:18:01 +10:00
2020-10-22 11:53:16 +02:00
2020-06-16 22:02:24 +10:00
2020-04-20 10:32:49 +10:00
2020-08-29 15:18:01 +10:00
2020-02-28 10:33:03 +11:00
2020-11-12 15:04:53 +11:00
2021-01-31 17:48:59 +01:00
2020-02-28 10:33:03 +11:00
2020-10-10 00:16:26 +11:00
2020-11-24 01:07:17 +11:00
2020-01-12 10:34:10 +11:00
2021-03-31 00:26:01 +11:00
2020-12-14 13:57:15 +11:00
2020-02-28 10:33:03 +11:00
2020-06-02 15:42:20 +10:00
2020-04-23 11:24:25 +10:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2021-03-26 13:48:34 +11:00
2020-12-14 13:30:56 +11:00
2020-04-05 15:02:06 +10:00
2020-04-05 15:02:06 +10:00
2020-05-28 10:02:14 +10:00
2020-04-05 15:02:06 +10:00
2020-04-23 11:24:25 +10:00
2021-04-19 00:11:51 +10:00
2018-05-01 15:53:25 +10:00
2020-09-18 17:20:34 +10:00
2020-12-07 23:32:06 +11:00
2020-02-28 10:33:03 +11:00
2017-07-31 18:35:40 +10:00
2020-08-02 22:34:09 +10:00
2020-02-28 10:33:03 +11:00
2021-02-08 11:50:05 +11:00
2020-03-11 14:34:40 +11:00
2020-04-18 22:36:14 +10:00
2020-05-14 21:48:05 +10:00
2020-02-28 10:33:03 +11:00
2021-03-11 12:51:10 +11:00
2021-03-11 12:51:10 +11:00
2020-02-28 10:33:03 +11:00
2017-12-28 16:46:30 +11:00
2020-02-28 10:33:03 +11:00
2021-03-11 12:51:10 +11:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2020-06-27 01:03:10 +10:00
2020-10-10 00:16:26 +11:00
2021-03-26 13:48:34 +11:00
2020-09-25 12:23:11 +10:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2021-03-26 13:48:34 +11:00
2020-06-27 01:03:10 +10:00
2020-04-05 15:02:06 +10:00
2021-03-26 13:48:34 +11:00
2020-02-28 10:33:03 +11:00
2021-04-23 22:03:46 +10:00
2020-02-28 10:33:03 +11:00
2019-02-12 14:54:51 +11:00
2021-02-04 22:46:42 +11:00
2021-01-29 23:57:10 +11:00
2019-08-30 16:44:12 +10:00
2020-06-30 23:55:32 +10:00
2017-07-31 18:35:40 +10:00
2021-03-26 13:48:34 +11:00
2020-05-28 10:02:14 +10:00
2020-11-11 22:18:24 +11:00
2021-02-04 22:46:42 +11:00
2020-05-28 10:02:14 +10:00
2020-04-05 15:02:06 +10:00
2018-03-13 14:03:15 +11:00
2019-02-12 14:54:51 +11:00
2020-09-04 00:10:24 +10:00
2020-02-11 15:43:13 +11:00
2020-04-23 11:24:25 +10:00
2017-11-20 09:30:06 +02:00
2020-01-13 01:01:45 +11:00
2020-04-05 15:02:06 +10:00
2017-10-04 12:37:50 +11:00
2020-02-28 10:33:03 +11:00
2021-03-26 13:48:34 +11:00
2019-02-12 14:54:51 +11:00
2020-10-22 11:53:16 +02:00
2019-12-27 12:53:36 +11:00
2020-04-13 22:19:37 +10:00
2020-12-07 23:32:06 +11:00
2020-02-28 10:33:03 +11:00
2020-04-05 15:02:06 +10:00
2017-06-09 17:33:01 +03:00
2020-12-07 23:32:06 +11:00
2020-04-05 15:02:06 +10:00
2020-02-28 10:33:03 +11:00
2020-10-10 00:16:32 +11:00
2019-12-27 12:34:22 +11:00
2019-02-12 14:54:51 +11:00
2020-01-09 11:25:26 +11:00
2020-03-26 01:21:04 +11:00
2020-03-26 01:21:04 +11:00
2020-10-01 15:26:43 +10:00
2020-09-11 23:00:03 +10:00
2020-04-18 22:36:14 +10:00
2017-07-31 18:35:40 +10:00
2020-02-28 10:33:03 +11:00
2017-07-31 18:35:40 +10:00
2021-02-04 22:46:42 +11:00
2019-12-12 20:15:28 +11:00
2021-04-12 22:31:42 +10:00
2020-02-28 10:33:03 +11:00
2021-04-09 13:08:35 +10:00
2021-03-11 12:51:10 +11:00
2020-02-28 10:33:03 +11:00
2020-02-28 10:33:03 +11:00
2020-04-05 15:02:06 +10:00
2021-01-30 13:40:48 +11:00
2020-02-28 10:31:07 +11:00
2020-02-28 10:33:03 +11:00
2017-03-14 11:52:05 +11:00
2020-02-28 10:33:03 +11:00
2017-07-31 18:35:40 +10:00
2019-11-21 12:04:53 +11:00
2020-06-05 14:04:20 +10:00
2019-12-12 20:15:28 +11:00
2017-12-05 00:38:41 +02:00
2021-04-12 22:36:16 +10:00
2020-05-08 23:20:45 +10:00
2020-05-08 23:20:45 +10:00
2020-10-22 11:40:56 +02:00
2020-10-22 11:40:56 +02:00
2020-04-05 15:02:06 +10:00
2020-09-11 17:22:28 +10:00
2017-07-31 18:35:40 +10:00
2021-02-04 22:46:42 +11:00
2020-02-28 10:33:03 +11:00
2017-07-31 18:35:40 +10:00
2020-04-27 23:58:46 +10:00
2020-03-25 01:00:52 +11:00
2020-02-28 10:33:03 +11:00
2017-09-06 16:43:09 +10:00
2021-03-31 00:26:01 +11:00
2021-03-17 12:13:53 +11:00
2020-10-22 11:47:36 +02:00
2020-02-28 10:33:03 +11:00
2019-02-06 00:19:00 +11:00