Skip to content

Adding CrazyLocals for importing stuff automatically #636

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

Closed
wants to merge 2 commits into from

Conversation

eliasdorneles
Copy link
Contributor

So, this is a really bad idea.

This makes names from sys.modules magically available without
needing to import them.

It does that by replacing the locals dict by a dict subclass that looks
up names in sys.modules when they're not present in current locals.

Please do NOT merge!

But have fun. :)

@thomasballinger
Copy link
Member

I'm surprised and confused about this working in Python 2!

I'm sort of curious about the failing tests in Python 2.7, I glanced at them and I didn't understand what was broken. No pressure for this not-going-to-be-merged PR, but if you look at them maybe leave a comment about what broke.

So, this is a really bad idea.

This makes names from sys.modules magically available without
needing to import them.

It does that by replacing the locals dict by a dict subclass that looks
up names in sys.modules when they're not present in current locals.

Please do NOT merge!

But have fun. :)
@eliasdorneles
Copy link
Contributor Author

I was just looking into the tests, the problem is that some expectations fail because some tests are expecting some names to not be defined.

For test_traceback I could see what's going on: it expects to see a NameError when calling g() in a new interpreter, but the actual exception is TypeError: 'int' object is not callable -- which I figure means some module available in the path during test run has a global g constant. :)

For the other errors, they're trying to get the line with error by causing a NameError using abc. But with crazy locals, abc gives you <module 'abc' from '/usr/lib/python2.7/abc.pyc'>. 🤘

I'm pushing a fix changing the names abcd and gfunc. :)

@thomasballinger
Copy link
Member

Ah cool, that all makes sense. Wow, thanks for changing all those tests. I wonder if we should merge the changes to tests anyway since this is a conceivable way that things could fail?

It probably goes without saying that this isn't getting merged. What about as a module? The changes you make in bpython/curtsiesfrontend/interpreter:Interpreter could be monkeypatched in, so this could be a bpython-autoimport plugin of sorts.

@eliasdorneles
Copy link
Contributor Author

Hm, I don't know, doesn't it seem like a maintenance headache? :)

I'll send a second PR with the test changes.

@thomasballinger
Copy link
Member

thomasballinger commented Sep 29, 2016

@eliasdorneles sure, but only a maintenance headache for you, not bpython! :)

@eliasdorneles
Copy link
Contributor Author

Haha, right!
I'll see how to make a module, just for fun! :)

@thomasballinger
Copy link
Member

Closing to reduce confusion

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.

2 participants