Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Check number of parameters: int.from_bytes() #6419

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

Closed
rsbohn opened this issue May 22, 2022 · 4 comments
Closed

Check number of parameters: int.from_bytes() #6419

rsbohn opened this issue May 22, 2022 · 4 comments
Labels
bug cpython api modules from cpython good first issue Hacktoberfest Beginner friendly issues for Hacktoberfest event help wanted
Milestone

Comments

@rsbohn
Copy link

rsbohn commented May 22, 2022

CircuitPython version

Adafruit CircuitPython 7.3.0-rc.2 on 2022-05-21; Raspberry Pi Pico with rp2040

Code/REPL

b = (0xFEED).to_bytes(2,"little")
# next line is not correct code
x = int.from_bytes(b, 2, "little")
print(x==0xFEED)

Behavior

C Python raises a TypeError if too many arguments:

int.from_bytes(bytes([0xFE,0xED]), 2, "big")
Traceback (most recent call last):
File "", line 1, in
TypeError: from_bytes() takes exactly 2 positional arguments (3 given)

Description

Expectation: Raise TypeError int.from_bytes() is called with more or less than 2 arguments.

Additional information

No response

@rsbohn rsbohn added the bug label May 22, 2022
@rsbohn
Copy link
Author

rsbohn commented May 23, 2022

Maybe adding some examples to the documentation would be enough:

int.from_bytes(b"\x00\x01","little") # returns 256
int.from_bytes(b"\x00\x01","big") # returns 1

(1).to_bytes(2,"little") # returns b'\x01\x00'
(1).to_bytes(2,"big") # returns b'\x00\x01'

@tannewt tannewt added this to the Long term milestone May 23, 2022
@tannewt
Copy link
Member

tannewt commented May 23, 2022

from_bytes source is here:

STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {

odaki pushed a commit to odaki/circuitpython that referenced this issue May 25, 2022
This changes makemanifest.py & mpy-tool.py to merge string and mpy names
into the same list (now mp_frozen_names).

The various paths for loading a frozen module (mp_find_frozen_module) and
checking existence of a frozen module (mp_frozen_stat) use a common
function that searches this list.

In addition, the frozen lookup will now only take place if the path starts
with ".frozen", which needs to be added to sys.path.

This fixes issues adafruit#1804, adafruit#2322, adafruit#3509, adafruit#6419.

Signed-off-by: Jim Mussared <[email protected]>
@adafruit-adabot adafruit-adabot added the Hacktoberfest Beginner friendly issues for Hacktoberfest event label Sep 29, 2022
@skerr92
Copy link

skerr92 commented Oct 16, 2022

Appears to be fixed by #6562

@dhalbert
Copy link
Collaborator

Thanks! Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cpython api modules from cpython good first issue Hacktoberfest Beginner friendly issues for Hacktoberfest event help wanted
Projects
None yet
Development

No branches or pull requests

5 participants