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

Check if string_names is None before returning string_names #1708

Merged
merged 5 commits into from Dec 12, 2020

Conversation

Leo-Ryu
Copy link
Contributor

@Leo-Ryu Leo-Ryu commented Dec 11, 2020

Hello!

I'm using jedi for a personal project, and I was getting this error when generating references of a class.

This PR simply checks if self.string_names is None and returns an empty list if so-- it solves the issue on my personal project so I thought it might be of some use to others.

  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/api/helpers.py", line 487, in wrapper
    return func(self, line, column, *args, **kwargs)
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/api/__init__.py", line 529, in get_references
    return _references(**kwargs)
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/api/__init__.py", line 523, in _references
    names = find_references(self._get_module_context(), tree_name, scope == 'file')
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/references.py", line 150, in find_references
    new = _dictionarize(_find_names(module_context, name_leaf))
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/references.py", line 75, in _find_names
    found_names = set(name.goto())
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/names.py", line 155, in goto
    module_names = goto_import(context, name)
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/cache.py", line 44, in wrapper
    rv = function(obj, *args, **kwargs)
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/imports.py", line 77, in goto_import
    _prepare_infer_import(module_context, tree_name)
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/imports.py", line 115, in _prepare_infer_import
    importer = Importer(module_context.inference_state, tuple(import_path),
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/imports.py", line 177, in __init__
    base = module_context.get_value().py__package__()
  File "/Users/lryu/.local/share/virtualenvs/python-parser-S0EswWrV/lib/python3.8/site-packages/jedi/inference/value/module.py", line 186, in py__package__
    return self.string_names[:-1]

@davidhalter
Copy link
Owner

Thanks for the fix! Is there a way we can regression test this, so it won't happen again in the future?

@codecov-io
Copy link

codecov-io commented Dec 11, 2020

Codecov Report

Merging #1708 (4e5bd33) into master (42a759a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1708   +/-   ##
=======================================
  Coverage   94.52%   94.52%           
=======================================
  Files          79       79           
  Lines       11762    11764    +2     
=======================================
+ Hits        11118    11120    +2     
  Misses        644      644           
Impacted Files Coverage Δ
jedi/inference/value/module.py 99.21% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 42a759a...4e5bd33. Read the comment docs.

@Leo-Ryu
Copy link
Contributor Author

Leo-Ryu commented Dec 11, 2020

@davidhalter Happy to help! I implemented a simple test-- let me know if you'd like something more complex

@davidhalter
Copy link
Owner

davidhalter commented Dec 11, 2020

flake8 fails: https://travis-ci.org/github/davidhalter/jedi/jobs/748914635

Test is fine I guess, will have to check if it actually changed the coverage.

@davidhalter davidhalter merged commit fd435a7 into davidhalter:master Dec 12, 2020
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 this pull request may close these issues.

None yet

3 participants