microsoft / vscode-black-formatter

Formatting support for Python using the Black formatter
https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter
MIT License
150 stars 35 forks source link

Formatter adding extra characters to code #385

Closed TheWizardofGauze closed 10 months ago

TheWizardofGauze commented 10 months ago

I was working on a file today and when I attempted to save a new command for my bot, the auto formatting kept messing up my code when I would save forcing me to disable auto formatting.

Here's an example. Before:

@bot.command()
@commands.is_owner()
async def sync(ctx):
    await app_commands.CommandTree.sync(guild=discord.Object(id=172571071059329025))

After:

@bobot.command()
@commands.is_owner()
async def sync(ctx):
    await app_commands.CommandTree.sync(guild=discord.Object(id=172571071059329025))

It changes "bot" to "bobot" and actually will add another "bo" every time I hit save.

Another example I discovered while writing this. Before:

@bot.command()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.message.add_reaction("👋🏼")
    await bot.close()

After:

t.command()
@commands.is_owner()
async def shutdown(ctx):
    await ctx.message.add_reaction("👋🏼")
    await bot.close()

And if I save again:

tommand()
@

@commands.is_owner()
async def shutdown(ctx):
    await ctx.message.add_reaction("👋🏼")
    await bot.close()

I'm using the latest version of black(v2023.6.0) and VSCode version 1.84.2.

karthiknadig commented 10 months ago

@TheWizardofGauze I am not able to re-produce this locally. Please try Extension Bisect, to see if this is being triggered due to interference by some other extension: image

TheWizardofGauze commented 10 months ago

@karthiknadig Bisect says ms-python.python is causing it... I guess I'll try and report it? I did some more testing and got similar behavior from autopep8.

karthiknadig commented 10 months ago

@TheWizardofGauze Can you share a list of extensions you have? and your settings?

TheWizardofGauze commented 10 months ago

@karthiknadig Extensions:

Settings:

The rest of the settings are unmodified.

karthiknadig commented 10 months ago

Duplicate of https://github.com/microsoft/vscode-black-formatter/issues/389