question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

library support request: attrs

See original GitHub issue

One of the major reasons that I want to eventually have a python-in-the-browser option is so that I can easily share complex data structures between the frontend and the backend.

Problem: I currently define all my complex data structures with https://github.com/python-attrs/attrs, and brython cannot import this code 😃.

I think this is a great library to try to get Brython to run unmodified, because it is doing lots of standard Python and platform detection at startup time, and using various standard library modules; yet, it does no I/O, requires no other libraries; it’s purely for defining data structures, so it should work just as well in Brython as in CPython.

Just a few things I hit while trying to import it:

  • functools.partial()
  • sys.version_info
  • platform.python_implementation()

None of these things seem hard to implement individually but there are probably a dozen of them before it will import.

Thanks again for brython!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
PierreQuentelcommented, Feb 14, 2018

In branch “rewrite_classes”, this code now works correctly:

import attr

@attr.s
class SomeClass(object):
    a_number = attr.ib(default=42)
    list_of_numbers = attr.ib(default=attr.Factory(list))

    def hard_math(self, another_number):
        return self.a_number + sum(self.list_of_numbers) * another_number


sc = SomeClass(1, [1, 2, 3])
print(SomeClass(a_number=1, list_of_numbers=[1, 2, 3]))

assert sc.hard_math(3) == 19
assert sc == SomeClass(1, [1, 2, 3])
assert sc != SomeClass(2, [3, 2, 1])
0reactions
glyphcommented, Apr 25, 2018

It’s possible that you didn’t include brython_stdlib.js in your script (if I remove it I also have an error message related to a missing future module)

That is indeed the problem; when I add brython_stdlib.js, attrs works fine!

@hynek - time to add brython to attrs’ CI? 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python's Requests Library (Guide)
The requests library is the de facto standard for making HTTP requests in Python. It abstracts the complexities of making requests behind a...
Read more >
Support the "attrs" library · Issue #1698 · PyCQA/pylint - GitHub
My pull request for the case with arguments was merged to master but until recently it did not make its way to a...
Read more >
attrs 22.2.0 documentation
Type Annotations help you to write correct and self-documenting code. attrs has first class support for them, yet keeps them optional if you're...
Read more >
Creating a Request from the Institution
Requests can be created for users within your institution, including item-level requests, title-level requests, work order requests, general hold requests ...
Read more >
flask.Request — Flask API - GitHub Pages
The request object is a Request subclass and provides all of the attributes Werkzeug defines plus a few Flask specific ones. Methods¶. __init__...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found