python / cpython

The Python programming language
https://www.python.org
Other
63.49k stars 30.4k forks source link

adafruit_ads1x15.ads1115 not comaptible with globals()[pkg_trunc] = importlib.import_module(pkg_trunc) #87094

Closed 7b8d8117-981c-446b-aa57-bd20aa05d04d closed 3 years ago

7b8d8117-981c-446b-aa57-bd20aa05d04d commented 3 years ago
BPO 42928
Nosy @gvanrossum
Files
  • ada_dbg1.py: uses simple hardcoded import statements, the creation of ads1115 objects work fine
  • ada_dbg2.py: shows the issue, uses a loop to import a variable list of packages, which allows for more graceful error handling & messaging.
  • print_data.py: utility to make output of dir(object) easier for humans to read
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = None closed_at = created_at = labels = ['interpreter-core', 'type-bug', '3.9'] title = 'adafruit_ads1x15.ads1115 not comaptible with globals()[pkg_trunc] = importlib.import_module(pkg_trunc)' updated_at = user = 'https://bugs.python.org/jbrearley' ``` bugs.python.org fields: ```python activity = actor = 'gvanrossum' assignee = 'none' closed = True closed_date = closer = 'gvanrossum' components = ['Interpreter Core'] creation = creator = 'jbrearley' dependencies = [] files = ['49741', '49742', '49743'] hgrepos = [] issue_num = 42928 keywords = [] message_count = 4.0 messages = ['385069', '385070', '385071', '385073'] nosy_count = 2.0 nosy_names = ['gvanrossum', 'jbrearley'] pr_nums = [] priority = 'normal' resolution = 'third party' stage = 'resolved' status = 'closed' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue42928' versions = ['Python 3.9'] ```

    7b8d8117-981c-446b-aa57-bd20aa05d04d commented 3 years ago

    The first attached script ada_dbg1.py.txt which uses simple hardcoded import statements, the creation of ads1115 objects work fine. The second attached script ada_dbg2.py.txt uses a loop to import a variable list of packages, which allows for more graceful error handling & messaging.

    globals()[pkg_trunc] = importlib.import_module(pkg_trunc)

    The high level observation is that board, busio & adafruit_extended_bus objects continue to be correctly created after the import loop is done. Its just adafruit_ads1x15.ads1115 that does not like this import method.

    The same line of code creating ads10 gets error:
    Traceback (most recent call last):
    File "ada_dbg2.py", line 33, in
    ads10 = adafruit_ads1x15.ads1115.ADS1115(i2c_1, address=0x48)
    AttributeError: module 'adafruit_ads1x15' has no attribute 'ads1115'

    When I look at the global variables, from ads_dbg1.py, I see: 'adafruit_ads1x15': \<module 'adafruit_ads1x15' from '/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/init.py'>,

    When I look at the global variables, from ads_dbg2.py, I see: 'adafruit_ads1x15.ads1115': \<module 'adafruit_ads1x15.ads1115' from '/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/ads1115.py'>,

    So I tried doing the import without the .ads1115 appended, & got: 'adafruit_ads1x15': \<module 'adafruit_ads1x15' from '/home/pi/.local/lib/python3.7/site-packages/adafruit_ads1x15/init.py'>,

    But I still get an error.
    Traceback (most recent call last):
    File "ada_dbg2.py", line 33, in
    ads10 = adafruit_ads1x15.ads1115.ADS1115(i2c_1, address=0x48)
    AttributeError: module 'adafruit_ads1x15' has no attribute 'ads1115'

    I went through all 8 permutations of with/without the .ads1115 in the importlib.import_module statement, no luck.

    Comments?

    gvanrossum commented 3 years ago

    Sorry, this is not a help forum. Please try a user forum. Probably you have to find one with people using the Adafruit modules (and CircuitPython?).

    7b8d8117-981c-446b-aa57-bd20aa05d04d commented 3 years ago

    Hi Guido: So the Adafruit CircuitPython forum has already said they aren't really sure this is their issue or not, see: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/issues/66

    What else would I need to do to get this looked at by people knowledgeable in importlib.import_module?

    Regards, John Brearley 613-259-5622 (Home)

    From: Guido van Rossum Sent: 2021-01-14 11:03 AM To: brearley@bell.net Subject: [bpo-42928] adafruit_ads1x15.ads1115 not comaptible with globals()[pkg_trunc] = importlib.import_module(pkg_trunc)

    Guido van Rossum \guido@python.org\ added the comment:

    Sorry, this is not a help forum. Please try a user forum. Probably you have to find one with people using the Adafruit modules (and CircuitPython?).

    ---------- nosy: +gvanrossum resolution: -> third party stage: -> resolved status: open -> closed


    Python tracker \report@bugs.python.org\ \https://bugs.python.org/issue42928\


    gvanrossum commented 3 years ago

    They did not imply it was a bug, just that they don't know enough about Python to be able help you.

    As I said, this tracker is not a help forum (you're taking valuable time away from core developers). Try this forum: https://discuss.python.org/c/users/7 .