Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'list' object has no attribute 'is_python' error when run from python terminal/script #85

Closed
rbpatt2019 opened this issue Apr 16, 2020 · 5 comments · Fixed by #86
Closed

Comments

@rbpatt2019
Copy link

See here as well.

Basically, the below errors:

>>> import pythonfinder
>>> finder = pythonfinder.Finder()
>>> print(list(finder.find_all_python_versions(3, 7))
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/pythonfinder.py", line 323, in find_all_python_versions
    major=major, minor=minor, patch=patch, pre=pre, dev=dev, arch=arch, name=name
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/path.py", line 548, in find_all_python_versions
    values = list(self.get_pythons(sub_finder))
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/path.py", line 506, in get_pythons
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/path.py", line 506, in <listcomp>
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/path.py", line 499, in _get_all_pythons
    for python in self._filter_paths(finder):
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/path.py", line 491, in _filter_paths
    python_versions = finder(path)
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/python.py", line 289, in find_all_python_versions
    pythons = [p for p in pythons if p and p.is_python and p.as_python is not None]
  File "/Users/pattersonrb/.local/pipx/venvs/pdm/lib/python3.7/site-packages/pythonfinder/models/python.py", line 289, in <listcomp>
    pythons = [p for p in pythons if p and p.is_python and p.as_python is not None]
AttributeError: 'list' object has no attribute 'is_python'

But the following works as expected:

$ python3 -m pythonfinder --findall
Found python at the following locations:
3.8.2: 3.8.2 (None) @ /Users/xxx/.pyenv/versions/3.8.2/bin/python3
python3: 3.7.7 (None) @ /Users/xxx/.local/pipx/venvs/pdm/bin/python3
python3: 3.7.7 (None) @ /Users/xx/.local/pipx/venvs/pdm/bin/python3
3.7.7: 3.7.7 (None) @ /Users/xx/.pyenv/versions/3.7.7/bin/python3
python3: 3.7.3 (None) @ /usr/bin/python3
python2: 2.7.16 (None) @ /usr/bin/python2
python2.7: 2.7.16 (None) @ /usr/bin/python2.7

I suspect this is related to #24 but am surprised to see that the error when run in a python prompt/script, as the CLI works fine!

@frostming
Copy link
Member

@rbpatt2019 Would you bother to test against bugfix/85 branch to verify the fix? Much appreciated for that.

@rbpatt2019
Copy link
Author

Just tested against the branch. Unfortunately, not a fix! But here's some updates:

  1. Running python3 -m pythonfinder --findall from the command line still works
  2. Running print(list(finder.find_all_python_versions(3, 7)) in a python terminal fails, but with a different error now:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/pythonfinder.py", line 323, in find_all_python_versions
    major=major, minor=minor, patch=patch, pre=pre, dev=dev, arch=arch, name=name
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/path.py", line 548, in find_all_python_versions
    values = list(self.get_pythons(sub_finder))
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/path.py", line 506, in get_pythons
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/path.py", line 506, in <listcomp>
    pythons = [entry for entry in self._get_all_pythons(finder)]
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/path.py", line 499, in _get_all_pythons
    for python in self._filter_paths(finder):
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/path.py", line 491, in _filter_paths
    python_versions = finder(path)
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/models/python.py", line 288, in find_all_python_versions
    pythons = list(unnest(sub_finder(path) for path in self.paths))
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/utils.py", line 339, in unnest
    for sub in unnest(el_copy):
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/utils.py", line 339, in unnest
    for sub in unnest(el_copy):
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/utils.py", line 339, in unnest
    for sub in unnest(el_copy):
  [Previous line repeated 977 more times]
  File "/Users/pattersonrb/projects/pythonfinder/src/pythonfinder/utils.py", line 331, in unnest
    if isinstance(item, Iterable) and not isinstance(item, six.string_types):
  File "/Users/pattersonrb/.pyenv/versions/3.7.7/lib/python3.7/abc.py", line 139, in __instancecheck__
    return _abc_instancecheck(cls, instance)
RecursionError: maximum recursion depth exceeded in comparison
  1. Running print(list(finder.find_all_python_versions()) in a python terminal works as expected, with the following correct output:
[PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/3.8.2/bin/python3'), _children={'/Users/pattersonrb/.pyenv/versions/3.8.2/bin/python3': ...}, only_python=False, name='3.8.2', _py_version=PythonVersion(major=3, minor=8, patch=2, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.8.2')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/3.8.2/bin/python3', company=None, name='3.8.2'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3'), _children={'/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3': ...}, only_python=False, name='python3', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3', company=None, name='python3'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3.7'), _children={'/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3.7': ...}, only_python=False, name='python3.7', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/3.7.7/envs/test/bin/python3.7', company=None, name='python3.7'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/test/bin/python3'), _children={'/Users/pattersonrb/.pyenv/versions/test/bin/python3': ...}, only_python=False, name='python3', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/test/bin/python3', company=None, name='python3'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/test/bin/python3.7'), _children={'/Users/pattersonrb/.pyenv/versions/test/bin/python3.7': ...}, only_python=False, name='python3.7', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/test/bin/python3.7', company=None, name='python3.7'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/3.7.7/bin/python3'), _children={'/Users/pattersonrb/.pyenv/versions/3.7.7/bin/python3': ...}, only_python=False, name='3.7.7', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/3.7.7/bin/python3', company=None, name='3.7.7'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/Users/pattersonrb/.pyenv/versions/test/bin/python3'), _children={'/Users/pattersonrb/.pyenv/versions/test/bin/python3': ...}, only_python=False, name='test', _py_version=PythonVersion(major=3, minor=7, patch=7, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.7')>, architecture=None, comes_from=..., executable='/Users/pattersonrb/.pyenv/versions/test/bin/python3', company=None, name='test'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/usr/bin/python3'), _children={'/usr/bin/python3': ...}, only_python=False, name='python3', _py_version=PythonVersion(major=3, minor=7, patch=3, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('3.7.3')>, architecture=None, comes_from=..., executable='/usr/bin/python3', company=None, name='python3'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/usr/bin/python2'), _children={'/usr/bin/python2': ...}, only_python=False, name='python2', _py_version=PythonVersion(major=2, minor=7, patch=16, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('2.7.16')>, architecture=None, comes_from=..., executable='/usr/bin/python2', company=None, name='python2'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False), PathEntry(path=PosixPath('/usr/bin/python2.7'), _children={'/usr/bin/python2.7': ...}, only_python=False, name='python2.7', _py_version=PythonVersion(major=2, minor=7, patch=16, is_prerelease=False, is_postrelease=False, is_devrelease=False, is_debug=False, version=<Version('2.7.16')>, architecture=None, comes_from=..., executable='/usr/bin/python2.7', company=None, name='python2.7'), _pythons=defaultdict(None, {}), _is_dir=False, _is_executable=True, _is_python=True, is_root=False)]

Seems that specifying a major/minor version is throwing the bug! Hope this helps.
Let me know if you need anything else! I've got the bugfix/85 branch pip install -e .'d into a clean venv now, so I can pull/test any further changes.

Appreciate all the help!

@frostming
Copy link
Member

Finally reproduced in one of the test cases, can you please try again?

@rbpatt2019
Copy link
Author

That did the trick! Running from the terminal works (as always), and now it works in a python terminal, both with and without specifying the version.

I can either close this now, or you can when bugfix/85is merged!

Cheers!

@frostming
Copy link
Member

Great, I am merging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants