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

Marker name is a string, not a lexer token #286

Merged
merged 2 commits into from
Feb 26, 2022

Conversation

dimbleby
Copy link
Contributor

@dimbleby dimbleby commented Feb 6, 2022

Discovered incidentally while working on python-poetry/poetry#5156 - sometimes a marker name was set to a lexer token rather than a string which, for instance, defeats comparisons for equality.

@dimbleby dimbleby mentioned this pull request Feb 9, 2022
abn
abn previously requested changes Feb 11, 2022
Copy link
Member

@abn abn left a comment

Choose a reason for hiding this comment

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

Can we add some regression coverage for this one?

@dimbleby
Copy link
Contributor Author

I must admit that I'm struggling now to recall why this was a problem. Per https://lark-parser.readthedocs.io/en/latest/classes.html#lark.Token

The Token class inherits from Python’s str, so normal string comparisons and operations will work as expected.

which seems like it should be fine, and my attempts to demonstrate otherwise in unit test are failing.

I'd be inclined to merge this anyway - it can't possibly be wrong, can it? But I am unable to prove that it is necessary, so if you're feeling super-cautious I guess don't.

Maybe we sometimes end up with different tokens for the same thing? This looks like an accident, I wonder whether that could confuse things sometimes?!?

@dimbleby
Copy link
Contributor Author

I'm back on the trail... depending on where the parser is called from, you can end up with (eg) either Token(markers__MARKER_NAME, 'extra') or Token(MARKER_NAME, 'extra'); and these do not compare equal because they are not the same type of token

@dimbleby
Copy link
Contributor Author

testcase added

@sonarcloud
Copy link

sonarcloud bot commented Feb 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.5% 0.5% Duplication

Copy link
Member

@finswimmer finswimmer left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@finswimmer finswimmer merged commit 1ca974c into python-poetry:master Feb 26, 2022
@dimbleby dimbleby deleted the marker-name-string branch February 26, 2022 18:46
DavidVujic pushed a commit to DavidVujic/poetry-core that referenced this pull request Mar 26, 2022
* Marker name is a string, not a lexer token

* add unit test
bostonrwalker pushed a commit to bostonrwalker/poetry-core that referenced this pull request Aug 29, 2022
* Marker name is a string, not a lexer token

* add unit test
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.

3 participants