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

deque Error in MicroPython within ESP32 #16

Open
harryxu opened this issue Sep 14, 2024 · 3 comments
Open

deque Error in MicroPython within ESP32 #16

harryxu opened this issue Sep 14, 2024 · 3 comments

Comments

@harryxu
Copy link

harryxu commented Sep 14, 2024

Env:

MicroPython v1.23.0 on 2024-06-02; Generic ESP32S3 module with ESP32S3

Error:

  File "/lib/pysm/pysm.py", line 474, in add_state
  File "/lib/pysm/pysm.py", line 784, in validate_add_state
  File "/lib/pysm/pysm.py", line 790, in _validate_state_already_added
  File "/lib/pysm/pysm.py", line 48, in __init__
TypeError: can't convert float to int

Through investigation, I found that the issue was caused by patch_deque in pysm using float('Inf') as the maxlen parameter for deque.

pysm/pysm/pysm.py

Lines 47 to 48 in b48cbc7

maxlen = float('Inf')
self.q = deque_module.deque(iterable, maxlen)

The following is the code I ran in the ESP32 shell, which resulted in the same error.

>>> from collections import deque
iterable = []
maxlen = float('Inf')
>>> deque(iterable, maxlen)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert float to int

@harryxu
Copy link
Author

harryxu commented Sep 14, 2024

@alhirzel Would it work correctly if we replace float('Inf') with sys.maxsize as the maxlen parameter?

@harryxu
Copy link
Author

harryxu commented Sep 14, 2024

@alhirzel Would it work correctly if we replace float('Inf') with sys.maxsize as the maxlen parameter?

I tried; it won’t work and will cause a memory error.

@thepartisan
Copy link

thepartisan commented Oct 19, 2024

I stumbled upon this when simply running the unit tests:

test/test_pysm.py:1423: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pysm.pysm.patch_deque.<locals>.deque_maxlen object at 0x7903f66f9460>, iterable = [], maxlen = inf

    def __init__(self, iterable=None, maxlen=0):
        # pylint: disable=no-member
        if iterable is None:
            iterable = []
        if maxlen in [None, 0]:
            maxlen = float('Inf')
            #maxlen = sys.maxsize
>       self.q = deque_module.deque(iterable, maxlen)
E       TypeError: an integer is required

pysm/pysm.py:49: TypeError

The proposal with sys.maxsizefixed at least the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants