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

py: Make dir report instance members #1756

Closed
wants to merge 1 commit into from

Conversation

dhylands
Copy link
Contributor

There currently doesn't seem to be any way to get a list of the instance variables. CPython reports this using dir(obj).

I'd like to be able to do something like:

regs = [isinstance(obj, Register) for obj in dir(self)]

@stinos
Copy link
Contributor

stinos commented Dec 29, 2015

+1 since I've had a similar patch lying around for a while now, though for me it's more useful to have __dict__ instead of dir - then again I'm not sure how useful this is for anyone else.. stinos@c1ebef2

@pfalcon
Copy link
Contributor

pfalcon commented Dec 29, 2015

@stinos : I wanted to tell you for a while: feel free to wrap it config define and submit. I was against adding it myself with the idea that it's useful mostly for initial stages of development, and that can be done on cpython instead, and then run on upy. But that doesn't work that well in practice - we have bunch of unsupported things, and bugs still too, so if an app is intended to be run on upy, it makes sense to develop it incrementally on upy too, and then __dict__ is useful.

@stinos
Copy link
Contributor

stinos commented Dec 29, 2015

config define

@pfalcon the MICROPY_CPYTHON_COMPAT one, or a new one?

@pfalcon
Copy link
Contributor

pfalcon commented Dec 29, 2015

I had in mind a separate option, but starting with MICROPY_CPYTHON_COMPAT should be good enough.

@dhylands
Copy link
Contributor Author

@stinos I'd be just as happy with dunder dict as using dir.

@dpgeorge
Copy link
Member

I think this is a good addition (independent of #1757). For example, microbit users were asking for this feature.

@pfalcon
Copy link
Contributor

pfalcon commented Jan 3, 2016

Merged, thanks!

@pfalcon pfalcon closed this Jan 3, 2016
tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Apr 9, 2019
Fix crash when getting board.SPI outside the VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants