Skip to content
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

DM-7199: afwTable's .getX()/.getY() do not appear in dir() #238

Merged
merged 2 commits into from
Jun 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/lsst/afw/table/base/baseContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ def asAstropy(self, cls=None, copy=False, unviewable="copy"):
)
return cls(columns, meta=meta, copy=False)

def __dir__(self):
"""
This custom dir is necessary due to the custom getattr below.
Without it, not all of the methods available are returned with dir.
See DM-7199
"""
def recursive_get_class_dir(cls):
"""
Return a set containing the names of all methods
for a given class *and* all of its subclasses.
"""
result = set()
if cls.__bases__:
for subcls in cls.__bases__:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this works, but the use of __bases__ feels exceptionally clever.

Does the MRO matter here at all? Probably not, since it's all going into a set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the... MRO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I don't think this matters, because it's all going into a set, and ultimately lands in a sorted list that excludes duplicates. And I choose to take "exceptionally clever" as a compliment, largely on Russell's behalf.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you are often much more clever writing code than trying to understand it later. That was the nature of my comment.

result |= recursive_get_class_dir(subcls)
result |= set(cls.__dict__.keys())
return result

return sorted(set(dir(self.columns)) | set(dir(self.table)) |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about the set operators (pipe for union, in this case). That's cool.

Separately, I think this return should be separated from the above by a line, since it's not part of that inner function.

recursive_get_class_dir(type(self)) | set(self.__dict__.keys()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just do set(self.__dict__) at the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed so, at least in python 3. I'm not sure if this would work in python 2 though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. Burned by py2 again.


def __getattr__(self, name):
# Catalog forwards unknown method calls to its table and column view
# for convenience. (Feature requested by RHL; complaints about magic
Expand Down