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

[BUG] rich.inspect on a module: AttributeError: Unknown C global variable '__class__' #1838

Closed
pbsds opened this issue Jan 16, 2022 · 4 comments · Fixed by #1842
Closed

[BUG] rich.inspect on a module: AttributeError: Unknown C global variable '__class__' #1838

pbsds opened this issue Jan 16, 2022 · 4 comments · Fixed by #1842
Assignees

Comments

@pbsds
Copy link
Contributor

pbsds commented Jan 16, 2022

Describe the bug

Trying to use rich.inspect on the module Faiss, (built by these guys) raises an AttributeError exception.

repro:

pip install --user faiss-cpu rich
python -c 'import rich, faiss; rich.inspect(faiss)'

output:

Click to expand
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/__init__.py", line 168, in inspect
    _console.print(_inspect)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/console.py", line 1621, in print
    extend(render(renderable, render_options))
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/console.py", line 1259, in render
    for render_output in iter_render:
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/panel.py", line 160, in __rich_console__
    else console.measure(
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/console.py", line 1212, in measure
    measurement = Measurement.get(self, options or self.options, renderable)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 107, in get
    get_console_width(console, options)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/padding.py", line 132, in __rich_measure__
    measure_min, measure_max = Measurement.get(console, options, self.renderable)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 107, in get
    get_console_width(console, options)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/console.py", line 468, in __rich_measure__
    return measure_renderables(console, options, self.renderables)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 142, in measure_renderables
    measurements = [
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 143, in <listcomp>
    get_measurement(console, options, renderable) for renderable in renderables
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 107, in get
    get_console_width(console, options)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/table.py", line 296, in __rich_measure__
    self._calculate_column_widths(
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/table.py", line 482, in _calculate_column_widths
    width_ranges = [
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/table.py", line 483, in <listcomp>
    self._measure_column(console, options, column) for column in columns
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/table.py", line 678, in _measure_column
    _min, _max = get_render_width(console, options, cell.renderable)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 107, in get
    get_console_width(console, options)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/padding.py", line 132, in __rich_measure__
    measure_min, measure_max = Measurement.get(console, options, self.renderable)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/measure.py", line 107, in get
    get_console_width(console, options)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/pretty.py", line 270, in __rich_measure__
    pretty_str = pretty_repr(
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/pretty.py", line 753, in pretty_repr
    node = traverse(_object, max_length=max_length, max_string=max_string)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/pretty.py", line 721, in traverse
    node = _traverse(_object, root=True)
  File "/home/pbsds/.cache/pypoetry/virtualenvs/foobar-u94_3CgC-py3.9/lib/python3.9/site-packages/rich/pretty.py", line 665, in _traverse
    elif isinstance(obj, _CONTAINERS):
  File "/usr/lib/python3.9/abc.py", line 119, in __instancecheck__
    return _abc_instancecheck(cls, instance)
AttributeError: Unknown C global variable '__class__'

Platform

Click to expand

Linux - Manjaro GNOME, using lxterminal

╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface.                                                  │
│                                                                                  │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=115 ColorSystem.TRUECOLOR>                                    │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                  │
│     color_system = 'truecolor'                                                   │
│         encoding = 'utf-8'                                                       │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│           height = 56                                                            │
│    is_alt_screen = False                                                         │
│ is_dumb_terminal = False                                                         │
│   is_interactive = True                                                          │
│       is_jupyter = False                                                         │
│      is_terminal = True                                                          │
│   legacy_windows = False                                                         │
│         no_color = False                                                         │
│          options = ConsoleOptions(                                               │
│                        size=ConsoleDimensions(width=115, height=56),             │
│                        legacy_windows=False,                                     │
│                        min_width=1,                                              │
│                        max_width=115,                                            │
│                        is_terminal=True,                                         │
│                        encoding='utf-8',                                         │
│                        max_height=56,                                            │
│                        justify=None,                                             │
│                        overflow=None,                                            │
│                        no_wrap=False,                                            │
│                        highlight=None,                                           │
│                        markup=None,                                              │
│                        height=None                                               │
│                    )                                                             │
│            quiet = False                                                         │
│           record = False                                                         │
│         safe_box = True                                                          │
│             size = ConsoleDimensions(width=115, height=56)                       │
│        soft_wrap = False                                                         │
│           stderr = False                                                         │
│            style = None                                                          │
│         tab_size = 8                                                             │
│            width = 115                                                           │
╰──────────────────────────────────────────────────────────────────────────────────╯
platform="Linux"
WindowsConsoleFeatures(vt=False, truecolor=False)
rich @ file:///home/pbsds/.cache/pypoetry/artifacts/1e/d2/56/58ed32503426d13d7f2181d73a291742842d3876c387b1f4ac2e3d2807/rich-10.16.2-py3-none-any.whl
@pbsds
Copy link
Contributor Author

pbsds commented Jan 16, 2022

Tangentially related: #1659

@willmcgugan
Copy link
Collaborator

This doesn't look like a problem with Rich per se, in that isinstance is not documented as being able to fail in that way. The failure is occurring when Rich does an isinstance check of a <Swig global variables> against an OS._Environ object. Which suggests an issue with Swig.

That said, Rich could probably work around that issue. I'll look in to it.

@github-actions
Copy link

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

@darrenburns
Copy link
Member

Hey @pbsds - we've merged a workaround for this that will be in the next release

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 31, 2022
11.1.0 - 2022-01-28

Added

Add Syntax.guess_lexer, add support for more lexers (e.g. Django templates etc.) Textualize/rich#1869
Add lexer parameter to Syntax.from_path to allow for overrides Textualize/rich#1873

Fixed

Workaround for edge case of object from Faiss with no __class__ Textualize/rich#1838
Ensure Syntax always justifies left Textualize/rich#1872
Handle classes in inspect when methods=True Textualize/rich#1874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants