Skip to content

Feature/long integer with underscores#923

Merged
davidism merged 2 commits intopallets:masterfrom
CleoQc:feature/long_integer_with_underscores
Jul 23, 2019
Merged

Feature/long integer with underscores#923
davidism merged 2 commits intopallets:masterfrom
CleoQc:feature/long_integer_with_underscores

Conversation

@CleoQc
Copy link
Copy Markdown
Contributor

@CleoQc CleoQc commented Nov 13, 2018

It is now possible to use the '_' character to make long integers and floats more easily understandable by a user.
100_000_000_000 for example, or 100_000_000_000.000_000_001

I don't think this closes any issue but since I had my hands in regex, it was a good timing,

@CleoQc
Copy link
Copy Markdown
Contributor Author

CleoQc commented Nov 13, 2018

@davidism : how would you prefer to handle this? This feature is limited to Python 3..6 and up. Currently it doesn't degrade nicely but I could fix that. Or ignore it.
Do you still want to support versions older than 3.6? I'm guessing yes.

I could make the regex dependent on the python version. I'm open to suggestions but I won't put any more work into this one until I get your feedback.

@davidism
Copy link
Copy Markdown
Member

We could support the underscore syntax for any version by removing them before calling literal_eval. Seems reasonable enough to do that.

@CleoQc
Copy link
Copy Markdown
Contributor Author

CleoQc commented Nov 13, 2018

Good point and should be simple enough to do.

@CleoQc
Copy link
Copy Markdown
Contributor Author

CleoQc commented Nov 13, 2018

Also of note, this PR contains the changes to #922 as they are literally on the same lines.

@CleoQc
Copy link
Copy Markdown
Contributor Author

CleoQc commented Nov 14, 2018

Finally passes all tests. Let me know if it's acceptable, please.

@CleoQc
Copy link
Copy Markdown
Contributor Author

CleoQc commented Nov 14, 2018

I've changed test_float and test_int but I'm thinking we should probably have a test_template that actually tests the regex.

Comment thread jinja2/lexer.py Outdated
Comment thread tests/test_filters.py Outdated
Comment thread docs/templates.rst Outdated
Comment thread docs/templates.rst Outdated
@davidism
Copy link
Copy Markdown
Member

I'll get to this eventually! I'm just focused on Werkzeug right now. :-)

CleoQc and others added 2 commits July 23, 2019 09:25
add changelog
clean up docs
parametrize tests
explain float regex
@davidism davidism force-pushed the feature/long_integer_with_underscores branch from 0ed6689 to 733851e Compare July 23, 2019 18:07
@davidism
Copy link
Copy Markdown
Member

Rebased onto current master + #922 changes. Explained the regex with verbose mode. Allow '_' in any part, which matches Python's grammar. Moved the tests out of filters and into lexer, since that's what this was about, but cleaned up both sets of tests with pytest.mark.parametrize.

@davidism davidism added this to the 2.11.0 milestone Jul 23, 2019
@davidism davidism merged commit 8e3c0e7 into pallets:master Jul 23, 2019
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants