On Thu, Oct 30, 2025 at 10:42:20AM +0100, Thomas Huth wrote:
> On 30/10/2025 10.33, Daniel P. Berrangé wrote:
> > On Thu, Oct 30, 2025 at 10:26:38AM +0100, Thomas Huth wrote:
> > > From: Thomas Huth <[email protected]>
> > > 
> > > The argparse.FileType() type has been deprecated in the latest argparse
> > > version (e.g. the one from Fedora 43), now causing the test_bad_vmstate
> > > functional test to fail since there are unexpected strings in the output.
> > > Change the script to use pathlib.Path instead to fix the test_bad_vmstate
> > > test and to be prepared for the future when the deprecated FileType gets
> > > removed completely.
> > > 
> > > Reported-by: Daniel P. Berrangé <[email protected]>
> > > Signed-off-by: Thomas Huth <[email protected]>
> > > ---
> > >   scripts/vmstate-static-checker.py | 13 +++++++------
> > >   1 file changed, 7 insertions(+), 6 deletions(-)
> > 
> > AFAICT, using pathlib.Path should work going back to any old python
> > versions we would need.
> 
> According to https://docs.python.org/3/library/pathlib.html it has been
> added with Python 3.4, and we require at least 3.9 nowadays, so yes, this
> should be fine.
> 
> > > @@ -393,10 +394,10 @@ def main():
> > >                           help='reverse the direction')
> > >       args = parser.parse_args()
> > > -    src_data = json.load(args.src)
> > > -    dest_data = json.load(args.dest)
> > > -    args.src.close()
> > > -    args.dest.close()
> > > +    with open(args.src, 'r', encoding='utf-8') as src_fh:
> > > +        src_data = json.load(src_fh)
> > > +    with open(args.dest, 'r', encoding='utf-8') as dst_fh:
> > > +        dest_data = json.load(dst_fh)
> > 
> > This could be
> > 
> >   src_data = json.load(args.src.read_text('utf-8'))
> >   dest_data = json.load(args.dest.read_text('utf-8'))
> 
> Does not work, looks like the load() function cannot deal with a string:
> 
> $ scripts/vmstate-static-checker.py -s
> tests/data/vmstate-static-checker/dump1.json -d
> tests/data/vmstate-static-checker/dump2.json
> Traceback (most recent call last):
>   File "../scripts/vmstate-static-checker.py", line 439, in <module>
>     sys.exit(main())
>              ~~~~^^
>   File "../scripts/vmstate-static-checker.py", line 397, in main
>     src_data = json.load(args.src.read_text('utf-8'))
>   File "/usr/lib64/python3.13/json/__init__.py", line 293, in load
>     return loads(fp.read(),
>                  ^^^^^^^
> AttributeError: 'str' object has no attribute 'read'

Sorry, I typod - it should be 'json.loads'  - note the trailing
's' for "string"

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to