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

dict-like Scope breaks locals() introspection #389

Closed
mahmoud opened this issue Oct 15, 2023 · 2 comments
Closed

dict-like Scope breaks locals() introspection #389

mahmoud opened this issue Oct 15, 2023 · 2 comments
Labels

Comments

@mahmoud
Copy link

mahmoud commented Oct 15, 2023

Hey there, long-time fan, first time filer.

The introduction of the dict-like Scope in #305 breaks a pattern I've used for a while, where the template simply echos the pprinted values of locals(). There's a test template here.

It fails with a NotImplementedError because pprint wants to use .items(). Here's a full traceback:

Traceback (most recent call last):
  File "/home/mahmoud/projects/clastic/.tox/py37/lib/python3.7/site-packages/chameleon/template.py", line 192, in render
    self._render(stream, econtext, rcontext)
  File "basic_template_78ff007bbb1662b17c111a0362aff5bd.py", line 152, in render
  File "/usr/lib/python3.7/pprint.py", line 58, in pformat
    compact=compact).pformat(object)
  File "/usr/lib/python3.7/pprint.py", line 144, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/usr/lib/python3.7/pprint.py", line 161, in _format
    rep = self._repr(object, context, level)
  File "/usr/lib/python3.7/pprint.py", line 393, in _repr
    self._depth, level)
  File "/usr/lib/python3.7/pprint.py", line 405, in format
    return _safe_repr(object, context, maxlevels, level)
  File "/usr/lib/python3.7/pprint.py", line 514, in _safe_repr
    vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level)
  File "/usr/lib/python3.7/pprint.py", line 511, in _safe_repr
    items = sorted(object.items(), key=_safe_tuple)
  File "/home/mahmoud/projects/clastic/.tox/py37/lib/python3.7/site-packages/chameleon/utils.py", line 427, in items
    raise NotImplementedError()
NotImplementedError

This fails on Python 3.7-3.9 at least, and chameleon==3.10 through master. (lines in question)

I'm hoping this acts as motivation to implement items(), assuming it's not prohibitively complex.

Thanks again!

@malthe
Copy link
Owner

malthe commented Oct 26, 2023

@mahmoud how does that work for you?

@mahmoud
Copy link
Author

mahmoud commented Nov 10, 2023

Hey, thanks for getting to this so quickly. Just checked the branch against my little set of tests and it's all green on this end. Thanks!

@malthe malthe closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants