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

Unexpected difference between cPython and Circuitpython when using count method on binary strings #9675

Open
kamocat opened this issue Oct 1, 2024 · 1 comment
Labels
bug cpython api modules from cpython
Milestone

Comments

@kamocat
Copy link

kamocat commented Oct 1, 2024

CircuitPython version

Adafruit CircuitPython 9.1.4 on 2024-09-17; Raspberry Pi Pico with rp2040

Code/REPL

a = b'A' * 32
print(a.count(b'A'))
print(a.count(65)) #A is ascii character 65

Behavior

The count function works with the byte string but not the integer. See:

32
Traceback (most recent call last):
  File "code.py", line 3, in <module>
TypeError: can't convert 'int' object to str implicitly

Description

In contrast, with cPython 3.12.6 in win32, the count works with both the integer and the byte string:

 >>> a = b'A' * 32
 >>> a.count(b'A')
 32
 >>> a.count(65)
 32

Additional information

https://docs.python.org/3/library/stdtypes.html#bytes.count states

The subsequence to search for may be any bytes-like object or an integer in the range 0 to 255.

@kamocat kamocat added the bug label Oct 1, 2024
@dhalbert
Copy link
Collaborator

dhalbert commented Oct 1, 2024

This behavior also exists in MicroPython, from which we take a lot of this kind of core functionality.

@dhalbert dhalbert added the cpython api modules from cpython label Oct 1, 2024
@dhalbert dhalbert added this to the Long term milestone Oct 1, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants