Coder Social home page Coder Social logo

Comments (7)

asottile avatar asottile commented on June 12, 2024

this was intentionally changed at some point. there are a few cases where it still leaves an else less one but when it deems it safe it can

from pyupgrade.

jvavrek avatar jvavrek commented on June 12, 2024

this was intentionally changed at some point. there are a few cases where it still leaves an else less one but when it deems it safe it can

Is it intentional that the behavior differs between the pre-commit hook and the command line, though?

Similarly, is it intentional/safe that it deletes the next comment?

from pyupgrade.

asottile avatar asottile commented on June 12, 2024

you are comparing 3.3.1 vs 3.15.0 what do you expect?

from pyupgrade.

jvavrek avatar jvavrek commented on June 12, 2024

you are comparing 3.3.1 vs 3.15.0 what do you expect?

Ok, if I update my local pyupgrade to 3.15.0, I get consistent behavior between the two---both delete the if block. However I still submit that there are two issues:

  1. The documentation is out of date
  2. pyupgrade incorrectly deletes the next comment after the if sys.version_info block

from pyupgrade.

asottile avatar asottile commented on June 12, 2024

the end of the block is not well defined when there's trialing comments -- pyupgrade picks the approach based on the information the tokenization hands it -- there isn't a correct choice because people do all sorts of flavors of:

if ...:
    code
    # comment

etc.

the docs aren't really out of date since there are still cases where it will leave an elseless branch alone -- but enumerating them in the docs isn't useful

from pyupgrade.

asottile avatar asottile commented on June 12, 2024

the case the docs is specifically referring to (where it will introduce a syntax error) is:

if True:
    if sys.version_info ...:
        ...

from pyupgrade.

jvavrek avatar jvavrek commented on June 12, 2024

Fair points, thanks.

from pyupgrade.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.