Skip to content
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

Circular fix applied involving Path and ComparePrimitivesByEqual #375

Closed
nth10sd opened this issue Aug 8, 2023 · 1 comment
Closed

Circular fix applied involving Path and ComparePrimitivesByEqual #375

nth10sd opened this issue Aug 8, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@nth10sd
Copy link

nth10sd commented Aug 8, 2023

Create a testcase.py file:

from pathlib import Path
from tempfile import TemporaryDirectory

with TemporaryDirectory() as f:
    fn_ = Path(f) / "test.txt"
    fn_.write_text("Testing!\n")

    assert fn_.read_text() == "Testing!\n"  # No fixit error

    assert (Path(f) / "test.txt").samefile(fn_)  # Assert passes, so they are identical
    assert (Path(f) / "test.txt").read_text() == "Testing!\n"  # fixit shows an error

Run the following command once:

grep "shows an error" testcase.py ; fixit lint --diff testcase.py ; fixit fix --automatic testcase.py ; grep "shows an error" testcase.py

You will get the first output:

    assert (Path(f) / "test.txt").read_text() == "Testing!\n"  # fixit shows an error
testcase.py@11:11 CompareSingletonPrimitivesByIs: Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identiy. Use `is` or `is not` instead. (has autofix)
--- a/testcase.py
+++ b/testcase.py
@@ -10,2 +10,2 @@
     assert (Path(f) / "test.txt").samefile(fn_)  # Assert passes, so they are identical
-    assert (Path(f) / "test.txt").read_text() == "Testing!\n"  # fixit shows an error
+    assert (Path(f) / "test.txt").read_text() is "Testing!\n"  # fixit shows an error
🛠️  1 file checked, 1 file with errors, 1 auto-fix available 🛠️
testcase.py@11:11 CompareSingletonPrimitivesByIs: Comparisons to singleton primitives should not be done with == or !=, as they check equality rather than identiy. Use `is` or `is not` instead. (has autofix)
🛠️  1 file checked, 1 file with errors, 1 auto-fix available, 1 fix applied 🛠️
    assert (Path(f) / "test.txt").read_text() is "Testing!\n"  # fixit shows an error

Run the command again, you will get this second set of fixes back to the original:

    assert (Path(f) / "test.txt").read_text() is "Testing!\n"  # fixit shows an error
testcase.py@11:11 ComparePrimitivesByEqual: Don't use `is` or `is not` to compare primitives, as they compare references. Use == or != instead. (has autofix)
--- a/testcase.py
+++ b/testcase.py
@@ -10,2 +10,2 @@
     assert (Path(f) / "test.txt").samefile(fn_)  # Assert passes, so they are identical
-    assert (Path(f) / "test.txt").read_text() is "Testing!\n"  # fixit shows an error
+    assert (Path(f) / "test.txt").read_text() == "Testing!\n"  # fixit shows an error
🛠️  1 file checked, 1 file with errors, 1 auto-fix available 🛠️
testcase.py@11:11 ComparePrimitivesByEqual: Don't use `is` or `is not` to compare primitives, as they compare references. Use == or != instead. (has autofix)
🛠️  1 file checked, 1 file with errors, 1 auto-fix available, 1 fix applied 🛠️
    assert (Path(f) / "test.txt").read_text() == "Testing!\n"  # fixit shows an error

Run the command over and over again, it will keep suggesting and applying the fix in the circular manner repeatedly.

libcst 1.0.1
fixit 2.0.0.post1

@amyreese amyreese added the bug Something isn't working label Aug 22, 2023
llllvvuu added a commit to llllvvuu/Fixit that referenced this issue Sep 7, 2023
…d of QualifiedName

fixes Instagram#378 and Instagram#375 which are caused by Instagram/LibCST#389.

Qualifying a name will never make some thing that wasn't already
True/False/None into a True/False/None:

```python
import libcst as cst
from libcst.metadata.name_provider import QualifiedNameProvider
from textwrap import dedent

wrapper = cst.MetadataWrapper(
    cst.parse_module(dedent(
    '''
        x = None
        x()
    '''
    ))
)
x_ref = wrapper.module.body[1].body[0].value
print(wrapper.resolve(QualifiedNameProvider)[x_ref]())
```
prints:
```python
{QualifiedName(name='x', source=<QualifiedNameSource.LOCAL: 3>)}
```
amyreese added a commit to llllvvuu/Fixit that referenced this issue Oct 17, 2023
…d of QualifiedName

fixes Instagram#378 and Instagram#375 which are caused by Instagram/LibCST#389.

Qualifying a name will never make some thing that wasn't already
True/False/None into a True/False/None:

```python
import libcst as cst
from libcst.metadata.name_provider import QualifiedNameProvider
from textwrap import dedent

wrapper = cst.MetadataWrapper(
    cst.parse_module(dedent(
    '''
        x = None
        x()
    '''
    ))
)
x_ref = wrapper.module.body[1].body[0].value
print(wrapper.resolve(QualifiedNameProvider)[x_ref]())
```
prints:
```python
{QualifiedName(name='x', source=<QualifiedNameSource.LOCAL: 3>)}
```

Co-authored-by: Amethyst Reese <[email protected]>
amyreese added a commit that referenced this issue Oct 17, 2023
…d of QualifiedName (#391)

fixes #378 and #375 which are caused by Instagram/LibCST#389.

Qualifying a name will never make some thing that wasn't already
True/False/None into a True/False/None:

```python
import libcst as cst
from libcst.metadata.name_provider import QualifiedNameProvider
from textwrap import dedent

wrapper = cst.MetadataWrapper(
    cst.parse_module(dedent(
    '''
        x = None
        x()
    '''
    ))
)
x_ref = wrapper.module.body[1].body[0].value
print(wrapper.resolve(QualifiedNameProvider)[x_ref]())
```
prints:
```python
{QualifiedName(name='x', source=<QualifiedNameSource.LOCAL: 3>)}
```

Co-authored-by: Amethyst Reese <[email protected]>
@amyreese
Copy link
Member

This should be fixed by #391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants