Skip to content

Use package-relative imports to avoid collisions with user code #382

@snarfed

Description

@snarfed

Hi @MarshalX et al! First off, thanks for building and maintaining this library. It's great!

When I first tried it just now, I immediately hit an ImportError. I have an atproto_firehose.py module in my project's root, and atproto doesn't use package-relative imports, so it tried to import its own atproto_firehose, got mine instead, and choked:

ImportError: Failed to import test module: test_atproto_firehose
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/loader.py", line 162, in loadTestsFromName
    module = __import__(module_name)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ryan/src/bridgy-fed/tests/test_atproto_firehose.py", line 28, in <module>
    import atproto_firehose
  File "/Users/ryan/src/bridgy-fed/atproto_firehose.py", line 27, in <module>
    from atproto import CAR, AtUri, FirehoseSubscribeReposClient, firehose_models, models, parse_subscribe_repos_message
  File "/Users/ryan/src/bridgy-fed/local/lib/python3.11/site-packages/atproto/__init__.py", line 11, in <module>
    from atproto_firehose import (
ImportError: cannot import name 'AsyncFirehoseSubscribeLabelsClient' from partially initialized module 'atproto_firehose' (most likely due to a circular import) (/Users/ryan/src/bridgy-fed/atproto_firehose.py)

You probably want to make all of your internal imports package-relative by adding a . to prevent this. Eg in this case, you'd do from .atproto_firehose import ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions