Comments (9)
Hello,
There is great chances that this is actually already fixed but unreleased (see: #44). Can you try using RedBaron master to see if this works please?
I'll do a bugfix release if it's the case.
Thanks for reporting :)
from redbaron.
I can reproduce the bug on master; zmq's sys.stdout
does have fileno()
, it just raises when called.
from redbaron.
This should be a simple matter of catching UnsupportedOperation
, however I do not understand why the isatty()
check is here to begin with. __repr__()
works differently depending on what sys.stdout
is, regardless of whether __repr__()
is going there or not?
from redbaron.
Yes, in a ipython shell, repr
displays the selected code (highlighted with pygment) like BeautifulSoup displays you the selected html. But when running a script you might not know where you are and what you have selected at this point so we display a more common repr (much like any python object).
I'm going to look at it in some minutes.
from redbaron.
The problem with that approach is that you have no accurate way of knowing if the result of __repr__
is eventually meant to be printed in the terminal or not. In IPython, the kernel is not attached to a terminal, and yet the result is sent through a ZMQ socket and printed. In contrast, a non-interactive function might still happen in a process which is still connected to a terminal.
The current approach already does weird stuff, for example:
>>> tree.help
<bound method NodeList.help of 0 self.get_input('some_port')
1 u'\n'
2 a = self.force_get_input('something', 2)
3 u'\n'
4 if False:
self.set_output('port_name', False)
>
AFAIK beautifulsoup doesn't try anything funny here either (link).
I'm not sure what to recommend though because __str__()
's output is indeed useful 😢
from redbaron.
Yes, BeautifulSoup always print the html code which is fine. In our case we sometime ends up printing formatting information like white spaces which turns out to be extremely confusing for the user.
So, after one quick google search "how to detect that you are in a python shell" we ends up with this situation that doesn't seems very optimal :/
Right now I don't know have an opinion on the best approach to have. I'll start by fixing it for ipython and catching other exceptions to fall back on a default behavior.
from redbaron.
After playing with "def repr_html" of the notebook this end up looking like this:
Should be way more usable. It's pushed on master.
Tell me if you find any more bugs ;)
from redbaron.
Closing this issue for now, don't hesitate to complain/reopen it/open other issues if needed.
from redbaron.
This is great, thanks 😃
from redbaron.
Related Issues (20)
- [BUG] `return` on the 1-2 indent levels levels inside of `try`/`except` resets the closes `except` level HOT 4
- replacing a call atom with a comprehension raises ParsingError
- ComprehensionLoopNode target/iterator attributes transposed
- Misleading AST for modulo operator combined with multiplication HOT 1
- Please add a LICENSE file
- Conversion to ast ASTs
- Incorrect parsing of Unicode Literals. Got - UntreatedError: Untreated elements
- Middle-ground betwixt `ast` and `baron` for parsing source code, and emitting only what changed in FST from AST HOT 1
- bug: Comments determine indent level of function body
- GroupingError on await expression
- RedBaron confuse relative path to ellipsis in from_imports
- py.test tests failing
- bug: Unpacking operator `*` used in list gives an error HOT 2
- support for walrus operator
- support for context manager tuple
- Unsupported positional-only argument syntax
- Indent of function docstrings always four spaces HOT 2
- Sort functions by their usage?
- FromImportNode modifyed in memory but not saved to the file
- bug: remove() doesn't perform well.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redbaron.