pytype icon indicating copy to clipboard operation
pytype copied to clipboard

No <module A> in module <module B>, referenced from <module C>

Open theahura opened this issue 2 years ago • 0 comments

I've been running into a really strange bug:

FAILED: /home/soot/code/soot/experimental/amol/pytype-circular-import/.pytype/pyi/persistence/__init__.pyi 
/home/soot/code/soot/experimental/amol/pytype-circular-import/env/bin/python3 -m pytype.single --imports_info /home/soot/code/soot/experimental/amol/pytype-circular-import/.pytype/imports/persistence.__init__.imports --module-name persistence.__init__ -V 3.8 -o /home/soot/code/soot/experimental/amol/pytype-circular-import/.pytype/pyi/persistence/__init__.pyi --analyze-annotated --nofail --quick /home/soot/code/soot/experimental/amol/pytype-circular-import/src/persistence/__init__.py
File "/home/soot/code/soot/experimental/amol/pytype-circular-import/src/persistence/__init__.py", line 5, in initialize: Couldn't import pyi for 'persistence.objects' [pyi-error]
  No raw_store in module persistence, referenced from 'persistence.objects'

For more details, see https://google.github.io/pytype/errors.html#pyi-error
ninja: build stopped: subcommand failed.
Leaving directory '.pytype'

I have a codebase with a directory structure that looks like this:

src/
    persistence/
        __init__.py
        objects.py
        raw_store.py

If I try to run pytype src/ or pytype src/persistence/ I get the error above. If I try to run pytype src/persistence/objects.py it works fine.

The code below reproduces the bug (using the same file structure):

persistence/init.py

import persistence.objects


def initialize():
  persistence.objects.initialize()

persistence/objects.py

# I suspect this circular import on __init__ is the issue but why is the error on raw_store? 
# and why would removing the raw_store import fix the issue?
import persistence 
import persistence.raw_store as raw_store


def initialize():
  pass

persistence/raw_store.py (empty file)

This is on pytype v2022.03.21

theahura avatar Mar 30 '22 00:03 theahura