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

fix: handle decorators after snakecode #185

Merged
merged 1 commit into from
Mar 15, 2023
Merged

Conversation

mbhall88
Copy link
Member

@mbhall88 mbhall88 commented Mar 9, 2023

Closes #144

@mbhall88 mbhall88 requested a review from bricoletc March 9, 2023 00:36
@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #185 (1d93558) into master (b5aa660) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #185   +/-   ##
=======================================
  Coverage   98.12%   98.12%           
=======================================
  Files          12       12           
  Lines        1014     1014           
  Branches      222      222           
=======================================
  Hits          995      995           
  Misses         10       10           
  Partials        9        9           
Flag Coverage Δ
unittests 98.02% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
snakefmt/parser/parser.py 97.79% <100.00%> (ø)

@bricoletc
Copy link
Collaborator

Will review this in the next few days

Copy link
Collaborator

@bricoletc bricoletc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This is the right fix IMO.
I wanted to check that this wasn't a 'hack'

But is correct - python's tokenizer parses '@' as an operator (tokenize.OP) because it's actually a matrix multiplication operator, as well as being used for function decoration.

So '@' used to end up in the buffer that was flushed in the case of a context_exit triggered specifically after a run block. This left black failing to parse a lone @. (Note after something like input:, buffer used to still contain a lone '@' but buffer flushing would not be triggered as context_exit is not called). Now we force '@' not to be present in the flushed buffer when calling context_exit (i.e. exiting a run block). We do return a Status containing @ though, but that's OK as it won't be recognised as a keyword, and we'll just continue parsing the snakefile.

Wrote this as a documentation if we ever come back to it.
Nice fix! 👍

@mbhall88
Copy link
Member Author

Ah didn't realise it was a matrix multiplication operator. I was confused as to why it was returned as an OP token.

Cheers!

@mbhall88 mbhall88 merged commit 32d6c53 into snakemake:master Mar 15, 2023
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.

Decorated functions lead to error
2 participants