Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
black
#1
it turns out that i do not like various details of how black formats my code. so, i hope this is just defaults that can be changed, somehow. i suppose that my use can just be limited to looking at the diff output, that might be enough. but there are quite many little details, making diff output be rather large and cumbersome to consider.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
An other color Blue💦
Test it out Blue online🔵 | Black online⚫.

There are config that can be used.
Black doc Wrote:Pro-tip: If you're asking yourself "Do I need to configure anything?" the answer is No. Black is all about sensible defaults.

If Black or Blue change a lot in your code then you don't follow PEP-8 coding style.
In my code the the formatter make minor changes(as i mostly follow PEP-8),if i don't like any i go quick in change manually the small changes needed.
Black doc Wrote:Black is a PEP 8 compliant opinionated formatter.
Black reformats entire files in place.
Style configuration options are deliberately limited and rarely added.
It doesn't take previous formatting into account (see Pragmatism for exceptions).
Reply
#3
(Oct-17-2022, 10:37 AM)snippsat Wrote: (as i mostly follow PEP-8)
i'm curious what you do different than PEP-8.

one of the things i do is lining up things vertically where they are already on multiple lines.
# like this:
    alpha = 'one'
    beta  = 'two'
    gamma = 3
but black ...
# does this:
    alpha = 'one'
    beta = 'two'
    gamma = 3
it changes most of the quotes from single to double on string literals. this is perhaps my greatest dislike.

it adds spaces after commas in argument lists but not at the ends where the enclosing parenthesis are. my style is to usually have no spaces, but where the spaces help, put them in all position, or verticalize it.

i was told it makes argument lists vertical, but i didn't see that happen.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(Oct-17-2022, 10:37 AM)snippsat Wrote: An other color Blue💦
how did you install this? it is not in the Ubuntu 20.04 repository and i still have not gotten pip to quit using the wrong directory.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
(Oct-17-2022, 10:37 AM)snippsat Wrote: Test it out Blue online🔵 | Black online⚫.
the black site works. the blue site sorta seems to, but has operational issues (i can't scroll all the way down, for one).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
(Oct-17-2022, 10:28 PM)Skaperen Wrote: how did you install this? it is not in the Ubuntu 20.04 repository and i still have not gotten pip to quit using the wrong directory
You most fix this it's just the normal way.
pip install blue
Quote:it changes most of the quotes from single to double on string literals. this is perhaps my greatest dislike.
Blue will only use single quotes or convert to it code use double quotes.
Test a messed up code.
# coin.py
import random
import time

class Coin:
    def __init__(self ):
      self.sideup="Heads"

    def toss(self):
            if random.randrange( 2)== 0:
              self.sideup =    "Heads"
            else:
              self.sideup= "Tails"

def toss_result(    ):
  my_coin=Coin( )
  print(f"This side is up: {my_coin.sideup}")
  print("I am tossing the coin...")
  time.sleep(4)
  my_coin.toss()
  print(f"This side is up: {my_coin.sideup}")

if __name__ == "__main__" :
  toss_result( )
After run Blue.
G:\div_code\answer
λ blue --help # Show help 
λ blue coin.py
reformatted coin.py

All done! ✨ 🍰 ✨
1 file reformatted.
# coin.py
import random
import time


class Coin:
    def __init__(self):
        self.sideup = 'Heads'

    def toss(self):
        if random.randrange(2) == 0:
            self.sideup = 'Heads'
        else:
            self.sideup = 'Tails'


def toss_result():
    my_coin = Coin()
    print(f'This side is up: {my_coin.sideup}')
    print('I am tossing the coin...')
    time.sleep(4)
    my_coin.toss()
    print(f'This side is up: {my_coin.sideup}')


if __name__ == '__main__':
    toss_result()
So work fine,think i change to Blue because like single quotes better.
Reply
#7
(Oct-18-2022, 01:56 PM)snippsat Wrote: think i change to Blue because like single quotes better.
The problem with single quotes is that you can't use contractions and possessive 's between single quotes, for example
sentence = "you can't use contractions and possessive 's"
It is even worse in french where articles and pronouns are contracted before a vowel, for example
phrase = "C'est l'arrivée de la course"
Aesthetically I'd like to switch to single quotes everywhere but I don't think it is a good idea.
Reply
#8
(Oct-18-2022, 06:00 PM)Gribouillis Wrote: Aesthetically I'd like to switch to single quotes everywhere but I don't think it is a good idea.
It's not a problem Blue will understand when it can not convert to single quotes.
# text_test.py
sentence = "you can't use contractions and possessive 's"
phrase = "C'est l'arrivée de la course"
can_change = "My car is blue"
print(sentence)
print(phrase)
print(can_change)
Run Blue.
G:\div_code\answer
λ blue text_test.py
reformatted text_test.py

All done! ✨ 🍰 ✨
1 file reformatted.
After the line that could changed to single quotes is changed.
# text_test.py
sentence = "you can't use contractions and possessive 's"
phrase = "C'est l'arrivée de la course"
can_change = 'My car is blue'
print(sentence)
print(phrase)
print(can_change)
Output:
you can't use contractions and possessive 's C'est l'arrivée de la course My car is blue
Reply
#9
(Oct-18-2022, 06:00 PM)Gribouillis Wrote:
(Oct-18-2022, 01:56 PM)snippsat Wrote: think i change to Blue because like single quotes better.
The problem with single quotes is that you can't use contractions and possessive 's between single quotes, for example
sentence = "you can't use contractions and possessive 's"
It is even worse in french where articles and pronouns are contracted before a vowel, for example
phrase = "C'est l'arrivée de la course"
Aesthetically I'd like to switch to single quotes everywhere but I don't think it is a good idea.
vous faites de bons points, surtout pour le français.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#10
pip worked this time. maybe it saw that i was logging it. but, now, black doesn't work. installing blue installed a newer version of black. looks like it is patched:

Output:
lt1a/phil/5 /home/phil 84> logcmd -s black-foo black foo.py Script started, file is ./20221018-155114-1525362-black-foo.log 15:51:14 [1525366] EXECUTING: 'black' 'foo.py' Traceback (most recent call last): File "/usr/local/bin/black", line 8, in <module> sys.exit(patched_main()) File "src/black/__init__.py", line 1423, in patched_main File "src/black/__init__.py", line 1409, in patch_click ImportError: cannot import name '_unicodefun' from 'click' (/usr/local/lib/python3.8/dist-packages/click/__init__.py) [[ 0m0s real 0.127 - user 0.103 - sys 0.024 - 99.88% ]] 15:51:14 [1525366] FINISHED - status = 1 Script done, file is ./20221018-155114-1525362-black-foo.log
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tools for black box and glass box (white box) testing Emekadavid 3 69,951 Jun-25-2020, 03:29 PM
Last Post: Emekadavid
  Has anyone tried the module Black ? Truman 7 5,243 Apr-17-2019, 02:11 AM
Last Post: Truman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020