Handling a function with the contextlib.contextmanager decorator that does not implement __enter__ or __exit__ ? #885
-
Working with the To improve performance, they grab a This leads to issues where utilizing the import psutil
my_process = psutil.Process() # gets the process with the current PID
with my_process.oneshot():
print(my_process.pid) # just print the PID Scanning this with tools like error: Object of type "None" cannot be used with "with" because it does not implement __enter__
...
error: Object of type "None" cannot be used with "with" because it does not implement __exit__ I'm wondering if this is something that needs to be fixed within the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
The typeshed stubs are incorrect: https://github.com/python/typeshed/blob/c0030b2b12738aefbbe71b857c20776b09d34e64/stubs/psutil/psutil/__init__.pyi#L90 |
Beta Was this translation helpful? Give feedback.
-
Semi related question, but what is the reason for doing from ._common import (
AIX as AIX,
BSD as BSD,
CONN_CLOSE as CONN_CLOSE,
CONN_CLOSE_WAIT as CONN_CLOSE_WAIT,
CONN_CLOSING as CONN_CLOSING,
CONN_ESTABLISHED as CONN_ESTABLISHED,
CONN_FIN_WAIT1 as CONN_FIN_WAIT1,
CONN_FIN_WAIT2 as CONN_FIN_WAIT2,
CONN_LAST_ACK as CONN_LAST_ACK,
CONN_LISTEN as CONN_LISTEN,
CONN_NONE as CONN_NONE,
CONN_SYN_RECV as CONN_SYN_RECV,
CONN_SYN_SENT as CONN_SYN_SENT,
CONN_TIME_WAIT as CONN_TIME_WAIT,
FREEBSD as FREEBSD,
LINUX as LINUX,
MACOS as MACOS,
NETBSD as NETBSD,
NIC_DUPLEX_FULL as NIC_DUPLEX_FULL,
NIC_DUPLEX_HALF as NIC_DUPLEX_HALF,
NIC_DUPLEX_UNKNOWN as NIC_DUPLEX_UNKNOWN,
OPENBSD as OPENBSD,
OSX as OSX,
POSIX as POSIX,
POWER_TIME_UNKNOWN as POWER_TIME_UNKNOWN,
POWER_TIME_UNLIMITED as POWER_TIME_UNLIMITED,
STATUS_DEAD as STATUS_DEAD,
STATUS_DISK_SLEEP as STATUS_DISK_SLEEP,
STATUS_IDLE as STATUS_IDLE,
STATUS_LOCKED as STATUS_LOCKED,
STATUS_PARKED as STATUS_PARKED,
STATUS_RUNNING as STATUS_RUNNING,
STATUS_SLEEPING as STATUS_SLEEPING,
STATUS_STOPPED as STATUS_STOPPED,
STATUS_TRACING_STOP as STATUS_TRACING_STOP,
STATUS_WAITING as STATUS_WAITING,
STATUS_WAKING as STATUS_WAKING,
STATUS_ZOMBIE as STATUS_ZOMBIE,
SUNOS as SUNOS,
WINDOWS as WINDOWS,
AccessDenied as AccessDenied,
Error as Error,
NoSuchProcess as NoSuchProcess,
TimeoutExpired as TimeoutExpired,
ZombieProcess as ZombieProcess,
) The only explanation I could find is in the CONTRIBUTING.md file where it says: Imports in stubs are considered private (not part of the exported API)
unless:
* they use the form ``from library import name as name`` (sic, using
explicit ``as`` even if the name stays the same); or
* they use the form ``from library import *`` which means all names
from that library are exported. And if I'm reading that correctly, you would only use |
Beta Was this translation helpful? Give feedback.
The typeshed stubs are incorrect: https://github.com/python/typeshed/blob/c0030b2b12738aefbbe71b857c20776b09d34e64/stubs/psutil/psutil/__init__.pyi#L90
PR welcome!