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
Incorrectly formats textwrap.dedent
#570
Comments
This is the only correct formatting, your suggested formatting changes the contents of the string: Taking the two examples above (I've dedented the xamples so it's more obvious what's different) dedent("""
Some text that
is split across multiple lines.
""")
dedent(
"""
Some text that
is split across multiple lines.
"""
) And then taking the strings from those: >>> x = """
... Some text that
... is split across multiple lines.
... """
>>> y = """
... Some text that
... is split across multiple lines.
... """
>>> x
'\n Some text that\n is split across multiple lines.\n'
>>> y
'\n Some text that\n is split across multiple lines.\n '
>>> x == y
False
>>> [(i, l1, l2) for i, (l1, l2) in enumerate(zip(x.split('\n'), y.split('\n'))) if l1 != l2]
[(3, '', ' ')] |
Would it make sense to special-case x = """
My multi-line
text that I want to
dedent.
""" then this should also be good style: x = dedent("""
My multi-line
text that I want to
dedent.
""") |
Black won't ever change your strings this way. |
@zsol the last example I provided didn't involve any change to the string. On the contrary, I'm just suggesting Black should not to try to do fancy formatting when it encounters a |
I don't understand why this is closed @zsol. Black seems to break my code here: import textwrap
def make_sbatch(name, cores, executable="run_learner.py", env="py37_min"):
job_script = textwrap.dedent(
f"""\
#!/bin/bash
#SBATCH --job-name {name}
#SBATCH --ntasks {cores}
#SBATCH --output {name}.out
#SBATCH --no-requeue
export MKL_NUM_THREADS=1
export OPENBLAS_NUM_THREADS=1
export OMP_NUM_THREADS=1
export MPI4PY_MAX_WORKERS=$SLURM_NTASKS
srun -n $SLURM_NTASKS --mpi=pmi2 ~/miniconda3/envs/{env}/bin/python3 -m mpi4py.futures {executable}
"""
)
return job_script
print(make_sbatch("test", 1)) It removes the Edit: I see #256 is still open. |
Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:
Operating system: OSX
Python version: 3.4, 3.5, 3.6
Black version: 18.9b0
Does also happen on master: yes
The text was updated successfully, but these errors were encountered: