[issue46512] Explicit or correct behavior of filecmp.cmpfiles w/ absolute path names

2022-01-25 Thread bers


New submission from bers :

It is very easy to use filecmp.cmpfiles incorrectly by passing absolute path 
names. This is because
1. the documentations does not say that relative path names have to be passed, 
and
2. filecmp.cmpfiles does not issue a warning when absolute path names are 
passed.

Consider this example code, which does look sensible at first glance:

files = dir_a.glob("*")
(equal, _, _) = filecmp.cmpfiles(dir_a, dir_b, files, shallow=False)
print("equal:", *equal)

However, in the full example below, you will see that this code fails to detect 
that two files are actually different.

"""Demo behavior of filecmp.cmpfiles with absolute path names."""
import filecmp
import tempfile
from pathlib import Path

with tempfile.TemporaryDirectory() as tmpdirname:
# prepare two different files
tmpdir = Path(tmpdirname)
dir_a = tmpdir / "a"
dir_b = tmpdir / "b"
file_a = dir_a / "foo.txt"
file_b = dir_b / "foo.txt"

dir_a.mkdir()
dir_b.mkdir()
file_a.write_text("A")
file_b.write_text("B")

# actually diff the files
files = dir_a.glob("*")
# filecmp should issue a warning here!
(equal, _, _) = filecmp.cmpfiles(dir_a, dir_b, files, shallow=False)
# otherwise, this result is easy to misinterpret - files are reported as 
equal
print("equal:", *equal)

--
components: Library (Lib)
messages: 411570
nosy: bers
priority: normal
severity: normal
status: open
title: Explicit or correct behavior of filecmp.cmpfiles w/ absolute path names
type: behavior
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue46512>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46512] filecmp.cmpfiles w/ absolute path names

2022-01-29 Thread bers


bers  added the comment:

> Did your example work with relative paths?

Yes, it does. Just append the following to my example code:

# actually diff the files - correctly!
files = [f.relative_to(dir_a) for f in dir_a.glob("*")]
(_, different, _) = filecmp.cmpfiles(dir_a, dir_b, files, shallow=False)
print("different:", *different)

Output then is

equal: C:\Users\bers\AppData\Local\Temp\tmp1p6jh4rg\a\foo.txt
different: foo.txt

--

___
Python tracker 
<https://bugs.python.org/issue46512>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36122] Second run of 2to3 continues to modify output

2019-02-26 Thread bers


New submission from bers :

I did this on Windows 10:

P:\>python --version
Python 3.7.2

P:\>echo print 1, 2 > Test.py

P:\>python Test.py
  File "Test.py", line 1
print 1, 2
  ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(1, 2)?

P:\>2to3 -w Test.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored Test.py
--- Test.py (original)
+++ Test.py (refactored)
@@ -1 +1 @@
-print 1, 2
+print(1, 2)
RefactoringTool: Files that were modified:
RefactoringTool: Test.py

P:\>python Test.py
1 2

P:\>2to3 -w Test.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored Test.py
--- Test.py (original)
+++ Test.py (refactored)
@@ -1 +1 @@
-print(1, 2)
+print((1, 2))
RefactoringTool: Files that were modified:
RefactoringTool: Test.py

P:\>python Test.py
(1, 2)

Note how "print 1, 2" first becomes "print(1, 2)" (expected), then becomes 
"print((1, 2))" in the following run. This changes the output of Test.py

--
components: 2to3 (2.x to 3.x conversion tool)
messages: 336653
nosy: bers
priority: normal
severity: normal
status: open
title: Second run of 2to3 continues to modify output
type: enhancement
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue36122>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36122] Second run of 2to3 continues to modify output

2019-02-26 Thread bers


bers  added the comment:

Yes, understood! Thanks for the explanation.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue36122>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com