Hello,
I would easily bet 10 bucks that vars() is the least known, and least
used, of the Python builtin functions.
My mental model of it was: it was introduced (perhaps in Python3) to
"harmonize" all the existing .__dict__ stuff, and provide more
abstract interface for it, with .__dict__ patiently waiting its
deprecation in CPython 10 or something.
Was I wrong with thinking like that, and finding that vars() was
already in the docs of CPython 1.4, the earliest doc version hosted at
python.org:
https://docs.python.org/release/1.4/lib/node26.html#SECTION00330000000000000000
So it seems it was around "always", but then the question is why both
vars() and .__dict__ are round for so long, and there was no
(successful) attempt to stop breaking object encapsulation e.g. on
transitioning to Python3000? Anybody has any references to the story of
them? I can't find anything relevant so far. I in particular made sure
to google for "vars site:python-history.blogspot.com" with 0 hits.
Expected clarification on ".__dict__ breaking object encapsulation":
Usually, object attributes are used to access "some small piece of data"
"stored inside" an object. .__dict__ is not like that. Depending on how
you look at it, its either-or:
1. A *metadata* about an object (object's representation as a dict),
and then it makes sense to use a dedicated access means for that
metadata, exactly what vars() provides.
2. Leak of an implementation detail, because a particular Python
implementation uses a dict as internal storage for modules, classes,
instances, and then .__dict__ just gives blatant access to this
internal storage, bypassing normal object semantics.
--
Best regards,
Paul mailto:pmiscml@gmail.com
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/JAFIBBUU5UE7VMX3SFYXQOHNK6TDZBV3/
Code of Conduct: http://python.org/psf/codeofconduct/
I would easily bet 10 bucks that vars() is the least known, and least
used, of the Python builtin functions.
My mental model of it was: it was introduced (perhaps in Python3) to
"harmonize" all the existing .__dict__ stuff, and provide more
abstract interface for it, with .__dict__ patiently waiting its
deprecation in CPython 10 or something.
Was I wrong with thinking like that, and finding that vars() was
already in the docs of CPython 1.4, the earliest doc version hosted at
python.org:
https://docs.python.org/release/1.4/lib/node26.html#SECTION00330000000000000000
So it seems it was around "always", but then the question is why both
vars() and .__dict__ are round for so long, and there was no
(successful) attempt to stop breaking object encapsulation e.g. on
transitioning to Python3000? Anybody has any references to the story of
them? I can't find anything relevant so far. I in particular made sure
to google for "vars site:python-history.blogspot.com" with 0 hits.
Expected clarification on ".__dict__ breaking object encapsulation":
Usually, object attributes are used to access "some small piece of data"
"stored inside" an object. .__dict__ is not like that. Depending on how
you look at it, its either-or:
1. A *metadata* about an object (object's representation as a dict),
and then it makes sense to use a dedicated access means for that
metadata, exactly what vars() provides.
2. Leak of an implementation detail, because a particular Python
implementation uses a dict as internal storage for modules, classes,
instances, and then .__dict__ just gives blatant access to this
internal storage, bypassing normal object semantics.
--
Best regards,
Paul mailto:pmiscml@gmail.com
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/JAFIBBUU5UE7VMX3SFYXQOHNK6TDZBV3/
Code of Conduct: http://python.org/psf/codeofconduct/