--- /dev/null
+.. change::
+ :tags: feature, sql
+
+ The Python builtin ``dir()`` is now supported for a SQLAlchemy "properties"
+ object, such as that of a Core columns collection (e.g. ``.c``),
+ ``mapper.attrs``, etc. Allows iPython autocompletion to work as well.
+ Pull request courtesy Uwe Korn.
def __iter__(self):
return iter(list(self._data.values()))
+ def __dir__(self):
+ return dir(super(Properties, self)) + [str(k) for k in self._data.keys()]
+
def __add__(self, other):
return list(self) + list(other)
from sqlalchemy import util, sql, exc, testing
from sqlalchemy.testing import assert_raises, assert_raises_message, fixtures
-from sqlalchemy.testing import eq_, is_, ne_, fails_if, mock, expect_warnings
+from sqlalchemy.testing import eq_, in_, is_, ne_, fails_if, mock
+from sqlalchemy.testing import expect_warnings
from sqlalchemy.testing.util import picklers, gc_collect
from sqlalchemy.util import classproperty, WeakSequence, get_callable_argspec
from sqlalchemy.sql import column
eq_(props._data, p._data)
eq_(props.keys(), p.keys())
+ def test_keys_in_dir(self):
+ data = {'hello': 'bla'}
+ props = util.Properties(data)
+ in_('hello', dir(props))
+
def test_pickle_immuatbleprops(self):
data = {'hello': 'bla'}
props = util.Properties(data).as_immutable()