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

'Symbols' object has no attribute 'namedexpr_test' #980

Closed
CuriousLearner opened this issue Aug 13, 2019 · 8 comments · Fixed by #981
Closed

'Symbols' object has no attribute 'namedexpr_test' #980

CuriousLearner opened this issue Aug 13, 2019 · 8 comments · Fixed by #981
Labels
T: bug Something isn't working

Comments

@CuriousLearner
Copy link

CuriousLearner commented Aug 13, 2019

Error: 'Symbols' object has no attribute 'namedexpr_test'

Operating system: OSX
Python version: 3.7
Black version: master
Does also happen on master:

To answer the last question, you have two options:

  1. Use the online formatter at https://black.now.sh/?version=master, which will use the latest master branch.
  2. Or run black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .;
    • make sure it's sane by running python setup.py test; and
    • run black like you did last time.

I've run this using pre-commit hooks which gives the following error:

black....................................................................Failed
hookid: black

error: cannot format /Users/sanyamkhurana/work/mymp/mymp/maps/serializers.py: 'Symbols' object has no attribute 'namedexpr_test'
error: cannot format /Users/sanyamkhurana/work/mymp/mymp/maps/models.py: 'Symbols' object has no attribute 'namedexpr_test'
error: cannot format /Users/sanyamkhurana/work/mymp/mymp/maps/services.py: 'Symbols' object has no attribute 'namedexpr_test'
Oh no! 💥 💔 💥
1 file left unchanged, 3 files failed to reformat.

Note that if I install black using pip and try to reformat, these files are reformatted properly without any errors. The version I got from pip install is 19.3b0 which is working fine, but the master is breaking.

Here is my pre-commit-config.yaml

repos:
- repo: https://github.com/ambv/black
  rev: master
  hooks:
    - id: black
      language_version: python3.7

I've trimmed it for brevity. Please note that this was working fine 5 days earlier.

Please let me know if you need any more details.

@JelleZijlstra
Copy link
Collaborator

@zsol I'm guessing this is a result of the PEP 572 changes?

@CuriousLearner does this happen on all of your code or just on specific constructs?

@CuriousLearner
Copy link
Author

@JelleZijlstra This happens for all the changes that are in the git working tree.

I've also tried to modify my pre-commit-hooks to use stable instead of a master like:

repos:
- repo: https://github.com/ambv/black
  rev: stable
  hooks:
    - id: black
      language_version: python3.7

and it seems that it is able to easily work for all those files that were failed by the master.

@zsol zsol added the T: bug Something isn't working label Aug 13, 2019
@zsol
Copy link
Collaborator

zsol commented Aug 13, 2019

I'll take a look at this ASAP.

@zsol
Copy link
Collaborator

zsol commented Aug 13, 2019

This is likely because the grammar in the cache is not regenerated, but it should be. @CuriousLearner can you try blowing away $HOME/.cache/black and rerunning the precommit hook from master?

@zsol
Copy link
Collaborator

zsol commented Aug 13, 2019

We're relying on the fact that the cache is keyed by black.__version__, so this changes during a release. Maybe it should change per commit? I don't think we're making any reasonable precautions that would make cache-sharing between black versions in-between releases safe.

@JelleZijlstra
Copy link
Collaborator

If there is a good way to make the cache keyed by commit, that seems like the best solution.

Arguably people who run off master should be prepared for this sort of confusion, but we can hardly blame them for using master if we take so long between releases...

@zsol
Copy link
Collaborator

zsol commented Aug 13, 2019

Pandas does it like this which looks promising on the surface until you open up _version.py :D ... although it's a generated file...

@CuriousLearner
Copy link
Author

@zsol I couldn't find a cache for black in my home directory but I found one for pre-commit

$HOME/.cache/pre-commit so, I removed the entire cache, rebuilt my pre-commit hooks, and I was able to use the master version to succesfully reformat my files.

So, I think you're correct!

@zsol zsol closed this as completed in #981 Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants