kopia lustrzana https://github.com/micropython/micropython
3c4bfd1dec
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> |
||
---|---|---|
.. | ||
modules | ||
modules2/subpkg | ||
modules3 | ||
builtin_next_arg2.py | ||
core_class_delnotimpl.py | ||
core_class_mro.py | ||
core_class_supermultiple.py | ||
core_class_superproperty.py | ||
core_function_argcount.py | ||
core_function_userattr.py | ||
core_generator_noexit.py | ||
core_import_all.py | ||
core_import_path.py | ||
core_import_prereg.py | ||
core_import_split_ns_pkgs.py | ||
core_locals.py | ||
core_locals_eval.py | ||
modules_array_containment.py | ||
modules_array_deletion.py | ||
modules_array_subscrstep.py | ||
modules_deque.py | ||
modules_json_nonserializable.py | ||
modules_os_environ.py | ||
modules_os_getenv.py | ||
modules_os_getenv_argcount.py | ||
modules_struct_fewargs.py | ||
modules_struct_manyargs.py | ||
modules_sys_stdassign.py | ||
syntax_assign_expr.py | ||
syntax_spaces.py | ||
syntax_unicode_nameesc.py | ||
types_bytearray_sliceassign.py | ||
types_bytes_format.py | ||
types_bytes_keywords.py | ||
types_bytes_subscrstep.py | ||
types_dict_keys_set.py | ||
types_exception_attrs.py | ||
types_exception_chaining.py | ||
types_exception_instancevar.py | ||
types_exception_loops.py | ||
types_exception_subclassinit.py | ||
types_float_rounding.py | ||
types_int_subclassconv.py | ||
types_list_delete_subscrstep.py | ||
types_list_store_noniter.py | ||
types_list_store_subscrstep.py | ||
types_str_endswith.py | ||
types_str_formatsubscr.py | ||
types_str_keywords.py | ||
types_str_ljust_rjust.py | ||
types_str_rsplitnone.py | ||
types_str_subscrstep.py | ||
types_tuple_subscrstep.py |