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
Use lowercase hex numbers fixes #1692 #1775
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't do a deep check on the code, but I did notice a few stylistic things.
src/black/__init__.py
Outdated
# All possible string prefix characters. | ||
STRING_PREFIX_CHARS: Final = "furbFURB" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: IMO this is unnecessary and just ruins blame information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was a result of autoformatter. I see the point. will revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (also all the rest)
src/black/__init__.py
Outdated
# Can be a container node with the `leaf`. | ||
first = ignored_nodes[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
src/black/__init__.py
Outdated
# Line is empty, don't emit. Creating a new one unnecessary. | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
.gitignore
Outdated
.venv/ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if the two extra empty lines were removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
.venv
Outdated
@@ -0,0 +1 @@ | |||
black |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this file for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was an error. sorry. should have been caught by the gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
# Leave octal and binary literals alone. | ||
pass | ||
elif text.startswith("0x"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this refactoring; to me it just creates an excessive number of small functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is fair - I relied on the Uncle Bob principle of "If you need a comment, then you should probably just have a more descriptive function name", but i might be misquoting or misunderstanding that. It is definitely a subjective matter. I liked the, in my opinion, higher level of readability, but the, already long, file gets longer which is maybe not cool. We can also drop the whole refactoring commit (or only take the formatting parts).
It's subjective :) I'll go with what you guys prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't hurt to add a comment to some of these if statements. E.g.:
elif "e" in text: # scientific notation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function, in my opinion, does exactly the same without duplication and without revealing implementation details. Is a general consesus that the functions decrease quality? As mentioned, i explicitly added it in a seperate commit to make it easy to drop :)
test_requirements.txt
Outdated
coverage >= 5.2.1 | ||
aiohttp >= 3.3.2 | ||
aiohttp-cors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these two additions needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - i was not able to run all the tests witout them :) Some tests rely on AIO stuff, so when i installed them i added them as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, CONTRIBUTING.md
suggests using pipenv, which includes them.
I'm not so familiar with pipenv, but I see Travis CI runs pip install -e '.[d]'
, where the d
is a so-called "extra" listed in setup.py
:
extras_require={
"d": ["aiohttp>=3.3.2", "aiohttp-cors"],
"colorama": ["colorama>=0.4.3"],
},
So that will install them for you. And GitHub Actions uses tox which also installs with the extra.
Want to try running pip install -e '.[d]'
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this requirements file is for CI not developers of Black. Doing a Pipenv developement install should install Black with its HTTP web server dependencies.
Line 21 in 4070527
black = {editable = true, extras = ["d"], path = "."} |
You get pinned dependencies too so doing a Pipenv development install is recommended
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oic. I use some...thing.. not actually sure. I simply realized it wasn't exhaustive, not that it was defined elsewhere. Should i remove these two lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another popular thing to do is to move tests dependencies from test_requirements.txt
into a tests
extra, for example:
But that's for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think remove those two lines to avoid duplication and keep things lean 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed :)
For the Primer failures: The CI is running Black on a few other projects to see if the formatting changes. Sometimes we don't want that to happen. In this case, some changes are expected. I checked a log, 5 projects now fail and they all look like hex number changes, as expected. To fix: flip |
@hugovk Thank you :) Should be fixed now. Regarding my refactoring, show i revert those? What is the general consesus? I can always revert it and then put it in another PR |
I completely forgot but please also add an entry in the change log, thank you! |
src/black/__init__.py
Outdated
|
||
|
||
def is_scientific_notation(text: str) -> bool: | ||
"""Checks if the supplied string is a number with scientific notation""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code matches 0xdeadbeef; it's an incorrect abstraction that depends on is_hex and other test having been applied earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid. Should i move all the checkers into the original function, while still moving the formatting into sub functions? Would that be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - But want other core devs completely happy too.
I'll update the changelog in less than 12 hours. I hope i can get a |
LGTM. To make me completely happy, I'd also revert the refactoring that creates three tiny functions that @JelleZijlstra pointed out. |
Whichh are these? I did revert the smallest of functions, but kept the formatting functions, as the numeric formatting already was in it's own function. This keeps it on the same level of abstraction, IMO. |
You're right, the formatting functions are fine. I was referring to the functions that only called |
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
I've mentioned it before, but didn't get any response: Will you add a hacktoberfest label? :P It's fine if you guys don't want to encourage it - I totally respect that. I'm just a bit pressed if i want to partake this year otherwise haha. |
This comment has been minimized.
This comment has been minimized.
Is this label all you need? |
|
* Made hex lower case * Refactored numeric formatting section * Redid some refactoring and removed bloat * Removed additions from test_requirements.txt * Primer now expects expected changes * Undid some refactoring * added to changelog * Update src/black/__init__.py Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com> Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com> Co-authored-by: Cooper Lees <me@cooperlees.com>
First PR onto black. Please tell me if i did something wrong according to your ordinary rules.
The issue, #1692, argues whether we/you should "simply" do this, as it might impact source code of a large set of users, however you can either merge it if you like it or wait if not. :) Please write me if I can do anything in that regard.
I created two seperate commits:
This was done to seperate the two focus points, the first one solves the issue, whereas the second adds a bit of refactoring to that part of the code. Whether my version has a higher code quality or not, is definitely subjective, so please ignore it and cherry-pick if you dislike it :)
I am looking forward to contributing to black, long time user, and all that, so I hope you like it. I'll try to do something once in a while - Am doing this as part of hacktoberfest though, so if you can either label it
hacktoberfest-accepted
or merge it before the end of the month, that will be great ;) I feel super cheap writing that, but i am trying to pimp my bike with a yearly sticker from hacktoberfest, and this month is running a bit short. If any changes are needed, I'll gladly make those :)Thank you!