jucapj / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Turn constants into Enums #469

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Future Python 3.4 will include enums:
http://www.python.org/dev/peps/pep-0435/
Long story short: all python constants in Python 3.4 now look like this:

>>> import socket
>>> socket.SOCK_STREAM
<SocketType.SOCK_STREAM: 1>
>>> 

That is a great step forward in terms of readability because in older Python 
version socket.SOCK_STREAM was just "1" and as such you couldn't immediately 
tell what that was while debugging:

python 2.7:

>>> import socket
>>> socket.socket()
<socket._socketobject object at 0x7f92d08598a0>

python 3.4:

>>> import socket
>>> socket.socket()
<socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketType.SOCK_STREAM, 
proto=0, laddr=('0.0.0.0', 0)>

Same thing applies to psutil. We have different integer constants such as:

>>> psutil.RLIMIT_AS
9
>>> 

...which we could turn into enums so that they'll look like this:

>>> psutil.RLIMIT_AS
<ProcessLimit.RLIMIT_AS: 1>
>>>

For Python versions < 3.4 we can integrate enum.py module straight into 
psutil/_compat.py.

Note to self: figure out what to do with string constants (psutil.CONN_ and 
psutil.STATUS_).

Original issue reported on code.google.com by g.rodola on 23 Jan 2014 at 9:39