suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

circular import #120

Open abtinmo opened 1 year ago

abtinmo commented 1 year ago

I installed the package on a freshly created environment and the first import raises an import error.


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/Programming/functional/.venv/lib/python3.9/site-packages/pfun/__init__.py", line 5, in <module>
    from . import clock, console, files, logging, random, state, subprocess  # noqa
  File "/Users/User/Programming/functional/.venv/lib/python3.9/site-packages/pfun/clock.py", line 6, in <module>
    from . import effect
ImportError: cannot import name 'effect' from partially initialized module 'pfun' (most likely due to a circular import) (/Users/User/Programming/functional/.venv/lib/python3.9/site-packages/pfun/__init__.py)
>>> ```
suned commented 1 year ago

Can you share what you were importing? I can't immediately reproduce this.

abtinmo commented 1 year ago

os: macos, fedora 38 python versions: 3.11, 3.9

my steps to reproduce the bug:

creating new env:

➜  python3 -m virtualenv .venv
created virtual environment CPython3.11.3.final.0-64 in 187ms
  creator CPython3Posix(dest=/Users/User/Programming/functional/.venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/User/Library/Application Support/virtualenv)
    added seed packages: pip==23.1.2, setuptools==67.7.2, wheel==0.40.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator

activating it

➜ source .venv/bin/activate

installing the package

(.venv) ➜ pip install pfun 
Collecting pfun
  Using cached pfun-0.13.0-cp311-cp311-macosx_13_0_arm64.whl
Collecting dill<0.4.0,>=0.3.2 (from pfun)
  Using cached dill-0.3.6-py3-none-any.whl (110 kB)
Collecting typing-extensions<4.0.0.0,>=3.10.0.0 (from pfun)
  Using cached typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, dill, pfun
Successfully installed dill-0.3.6 pfun-0.13.0 typing-extensions-3.10.0.2

running a python shell and importing the curry decorator

(.venv) ➜ python3                         
Python 3.11.3 (main, Apr  7 2023, 20:13:31) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pfun.functions import curry
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/Programming/functional/.venv/lib/python3.11/site-packages/pfun/__init__.py", line 5, in <module>
    from . import clock, console, files, logging, random, state, subprocess  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/User/Programming/functional/.venv/lib/python3.11/site-packages/pfun/clock.py", line 6, in <module>
    from . import effect
ImportError: cannot import name 'effect' from partially initialized module 'pfun' (most likely due to a circular import) (/Users/User/Programming/functional/.venv/lib/python3.11/site-packages/pfun/__init__.py)
>>> 
suned commented 1 year ago

Thank you! I'll investigate

sdaves commented 1 year ago

@suned Any update on this issue?

sdaves commented 1 year ago

@suned @abtinmo This is fixed with my pr #125