Skip to content

cpydiff: Document differences in errno and OSError. #17088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/cpydiff/modules_errno_enotsup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
categories: Modules,errno
description: Micropython does not include ``ENOTSUP`` as a name for errno 95.
cause: Micropython does not implement the ``ENOTSUP`` canonical alias for ``EOPNOTSUPP`` added in CPython 3.2.
workaround: Use ``errno.EOPNOTSUPP`` in place of ``errno.ENOTSUP``.
"""

import errno

print(f"{errno.errorcode[errno.EOPNOTSUPP]=!s}")
48 changes: 48 additions & 0 deletions tests/cpydiff/types_oserror_errnomap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
categories: Types,OSError
description: OSError constructor returns a plain OSError for all errno values, rather than a relevant subtype.
cause: Micropython does not include the CPython-standard OSError subclasses.
workaround: Catch OSError and use its errno attribute to discriminate the cause.
"""

import errno

errno_list = [ # i.e. the set implemented by micropython
errno.EPERM,
errno.ENOENT,
errno.EIO,
errno.EBADF,
errno.EAGAIN,
errno.ENOMEM,
errno.EACCES,
errno.EEXIST,
errno.ENODEV,
errno.EISDIR,
errno.EINVAL,
errno.EOPNOTSUPP,
errno.EADDRINUSE,
errno.ECONNABORTED,
errno.ECONNRESET,
errno.ENOBUFS,
errno.ENOTCONN,
errno.ETIMEDOUT,
errno.ECONNREFUSED,
errno.EHOSTUNREACH,
errno.EALREADY,
errno.EINPROGRESS,
]


def errno_output_type(n):
try:
raise OSError(n, "")
except OSError as e:
return f"{type(e).__name__}"
except Exception as e:
return f"non-OSError {type(e).__name__}"
else:
return "no error"


for n in errno_list:
print(errno.errorcode[n], "=", errno_output_type(n))
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy