You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is apparently because the new default __exit__ requires the presence of deinit in the object's dictionary, and I2CTargetRequest doesn't have one. It has a close() though, (which incidentally doesn't have a docstring).
Should I2CTargetRequest have a deinit() that calls common_hal_i2ctarget_i2c_target_close() and also maybe remove the close() method ?
The presence of the __del__ entry is true for all objects with a finaliser, which should be true for enter/exit objects. In i2ctarget_i2c_target_make_new(), the object created is created with mp_obj_malloc_with_finaliser().
I think the same pattern should be used for I2CTargetRequest: a deinit(), use mp_obj_malloc_with_finaliser(), and add the deinit and ___del__ to the method table.
I looked at the original PR, #1064, which mostly survives as is in the current code. I think the best thing to do here is to remove a user-accessible close() method, add deinit(), and have __exit__() call the common-hal target close() and then do a deinit(). I am working on a PR.
I'm curious - beyond searching the Adafruit and community bundles, is there any standard(-ish) process to search for method usage in a wider body of existing CircuitPython code? Obviously it needs to be something a bit more intelligent than simply grep close ..., but there are a variety of options for finding references to python method use that (try to and usually succeed at least partially) filter on the type, i.e. find invocations of close() on an I2CTargetRequest. But I'm not sure what you would search - searching github for CircuitPython currently returns nearly 4K repos, add MicroPython and you're pushing 17K. Is there any existing list of more widely used (but not in the Adafruit/community bundles) modules for testing / API deprecation checks?
Uh oh!
There was an error while loading. Please reload this page.
Since #10040 (9.2.5 and after) this happens with the i2ctarget example:
This is apparently because the new default
__exit__
requires the presence ofdeinit
in the object's dictionary, andI2CTargetRequest
doesn't have one. It has aclose()
though, (which incidentally doesn't have a docstring).Should
I2CTargetRequest
have adeinit()
that callscommon_hal_i2ctarget_i2c_target_close()
and also maybe remove theclose()
method ?circuitpython/shared/runtime/context_manager_helpers.c
Line 14 in d88fe10
circuitpython/shared-bindings/i2ctarget/I2CTarget.c
Lines 395 to 405 in d88fe10
The text was updated successfully, but these errors were encountered: