Giter VIP home page Giter VIP logo

Comments (7)

tomerfiliba avatar tomerfiliba commented on August 11, 2024

what's the exception?

from construct.

tdsparrow avatar tdsparrow commented on August 11, 2024

Full backtrack:

Traceback (most recent call last):
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 211, in build
self.build_stream(obj, stream)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 218, in build_stream
self._build(obj, stream, Container())
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 682, in _build
sc._build(subobj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 1133, in _build
self.subcon._build(obj, stream2, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 272, in _build
self.subcon._build(obj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 682, in _build
sc._build(subobj, stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/core.py", line 289, in _build
self.subcon._build(self._encode(obj, context), stream, context)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/adapters.py", line 51, in _encode
obj2 = int_to_bin(obj, width = self.width)
File "/home/erenlii/.local/lib/python2.7/site-packages/construct/lib/binary.py", line 116, in int_to_bin
i = width - 1
TypeError: unsupported operand type(s) for -: 'function' and 'int'

Here, width is the lambda from MetaField.

from construct.

tdsparrow avatar tdsparrow commented on August 11, 2024

For a quick fix, I added

        if callable(self.width):
            width = self.width(context)
        else:
            width = self.width

before file "/home/erenlii/.local/lib/python2.7/site-packages/construct/adapters.py", line 51, in _encode
obj2 = int_to_bin(obj, width = self.width)

from construct.

tomerfiliba avatar tomerfiliba commented on August 11, 2024

great! you can even make it shorter with obj2 = int_to_bin(obj, width = self.width(context) if callable(self.width) else self.width). could you test it and submit a pull request?

from construct.

tdsparrow avatar tdsparrow commented on August 11, 2024

Sure, i break it to pass pep8 check.
And is it the right place to fix? i'm not sure it can fix all problems with the same type.

from construct.

tomerfiliba avatar tomerfiliba commented on August 11, 2024

yeah, i think it's the right place. thanks!


Tomer Filiba
tomerfiliba.com http://www.facebook.com/tomerfiliba
http://il.linkedin.com/in/tomerfiliba

On Fri, Mar 28, 2014 at 4:24 AM, tdsparrow [email protected] wrote:

Sure, i break it to pass pep8 check.
And is it the right place to fix? i'm not sure it can fix all problems
with the same type.


Reply to this email directly or view it on GitHubhttps://github.com//issues/39#issuecomment-38880455
.

from construct.

arekbulski avatar arekbulski commented on August 11, 2024

This seems to have been patched a long time ago. Added regression test in a4eb053.

from construct.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.