What the agent does
plistlib.readPlist, writePlist and their FromBytes and ToBytes variants were removed in Python 3.9 in favour of load, loads, dump and dumps. The scripts that break are the ones that read iTunes libraries, Info.plist files and macOS preferences. The playlist project in electronut/pp, the code for the book Python Playground, is a typical one. playlist/playlist.py calls plistlib.readPlist(fileName) three times, on lines 29, 61 and 108, once in each of findCommonTracks, plotStats and findDuplicates, and the repository keeps five exported playlists in playlist/test-data/ to run it against.
The agent first records what correct output looks like, because the script has no tests. On Python 3.8, where the old function still exists and prints DeprecationWarning: The readPlist function is deprecated, use load() instead, it runs playlist.py --common on pl1.xml and pl2.xml and --dup on each sample file, and keeps the common.txt and dups.txt each one writes. On a current Python the same commands stop at line 108 or line 29 with the error in the title. The script imports matplotlib and numpy at the top, so both go into each environment first.
The replacement is not a rename, because the two functions take different arguments. readPlist accepted a path. load takes an open binary file, and passing it the path produces a second, more confusing error: AttributeError: 'str' object has no attribute 'read'. So each call becomes with open(fileName, 'rb') as fp: followed by plist = plistlib.load(fp). Text mode is wrong here even for XML plists, since load detects the format from the first bytes and binary plists are common on a Mac.
It then checks the one behaviour that differs between old and new. readPlist returned <data> elements wrapped in plistlib.Data objects, and load returns plain bytes. Code that reads .data on such a value breaks after the swap, and plistlib.Data is itself gone. The agent searches for .data and Data( near every plist value, and looks for <data> in the sample files. The five playlists in this fixture contain none, so here the swap is complete once the files match. It reruns every command on the new interpreter and compares common.txt and dups.txt, sorted, against the copies from 3.8.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This project fails on Python 3.9 or later with \"AttributeError: module 'plistlib' has no attribute 'readPlist'\". Find every use of plistlib.readPlist, writePlist, readPlistFromBytes, writePlistToBytes and plistlib.Data in the repository. Before changing anything, capture a baseline: on a Python version that still has these functions (3.8), run the program or its tests against the sample plist files in the repository and save the output. Then replace each call: readPlist(path) becomes plistlib.load on a file opened in 'rb' mode inside a with block, writePlist(obj, path) becomes plistlib.dump on a file opened in 'wb' mode, and the bytes variants become loads and dumps. Check what the old calls were given, since they accepted a path or a file object and the new ones accept only a binary file object. Look for code that depends on plistlib.Data wrappers or on attribute access to dictionary keys, because load returns plain bytes and plain dicts, and fix those call sites. If a write call relied on the default format, keep XML. Run the same commands on a current Python and compare the output with the baseline; order of lines in a file built from a set may differ, so compare sorted. Report anything else that fails on the current Python as a separate finding without fixing it. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request that, for a script like playlist.py, changes three call sites into three with blocks and nothing else. The description lists each replaced call with its line, shows the deprecation warning from the old interpreter and the traceback from the new one, and gives the comparison: the commands it ran on both, and that the sorted output files are identical.
It reports what it looked for and did not find. For this fixture that is one sentence saying no sample file has a <data> element and no code touches plistlib.Data, so the bytes difference does not apply. In a project that reads provisioning profiles or bookmarks, the same section lists the lines that needed a change from value.data to value.
Findings outside the task go in a separate list, unfixed. Reading findDuplicates turns one up here: the message printed to the terminal says the names were saved to dup.txt, while the file the function opens is dups.txt. The reviewer decides whether that belongs in this pull request. Before merging, they check that every open uses 'rb' or 'wb' and rerun one command from the description.
Run it on every Linear issue labelled python-upgrade
Breakage from an interpreter upgrade usually reaches a team as issues, one per script, filed by whoever ran it. Connect Linear in the console under Settings → Connections, then create an automation on the repository's Project with the prompt above and a linear trigger on linear.issue.labeled, with labels set to the label your team uses for this work. When a member of your Rush org adds the label, a run starts and the issue is added after the prompt as event text, so the traceback someone pasted into it reaches the agent.
The saved prompt is the only instruction, and the trigger fills in no placeholder, so write the prompt to cover the family of removed functions and let the issue supply the file. The automation's max runs per hour bounds a triage session in which many issues get the label at once: runs past the cap wait as queued and start when the hour has room, up to one more hour's worth.
The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.
Why run it on Rush?
The evidence for this fix is a comparison across two interpreters, and a laptop with a current Python no longer has the old one to produce the baseline. The agent installs both in its sandbox, along with matplotlib and numpy for each, runs the same commands on the same sample files, and keeps the outputs. Nothing about the developer's machine is changed, and the proof that results are identical travels with the pull request.
Scripts like these are also plentiful and individually small: a repository of utilities can hold many files that each read one plist. Each is its own run with its own short diff, and several can go at once without anyone context-switching between them. What comes back for each is a pull request short enough to read in one sitting, with the before and after outputs to check against.
Frequently asked questions
Why can't I pass a file path to plistlib.load?
load reads from a file object and calls .read() on what it is given. A path is a string, so the call fails with 'str' object has no attribute 'read'. Open the file in binary mode and pass the handle, or read the bytes yourself and use loads.
Does plistlib.load read binary plists?
Yes. It detects XML or binary from the start of the file when fmt is left unset, which is why the file must be opened with 'rb'. dump writes XML unless you pass fmt=plistlib.FMT_BINARY.
My code uses readPlistFromString. Is that the same fix?
That name is from Python 2, and a file that still uses it usually has other Python 2 syntax that fails first. The agent reports this instead of patching one line: the job becomes a port to Python 3, and it says so before doing anything larger than the prompt asked for.
Will the result still run on Python 3.8?
Yes. load and dump have been in plistlib since Python 3.4, so the new code runs on every version the old code ran on. The agent's baseline run on 3.8 is repeated with the new code to confirm it.
More jobs like this: Turn a Linear label into a PR
- Fix "DeprecationWarning: Redis.hmset() is deprecated. Use Redis.hset() instead" in a Python Service (redis-py)
- Fix "Return type should either be compatible with ArrayAccess::offsetGet" Deprecations on PHP 8.1 (PHP)
- Fix "Argument is deprecated: Use the aws_s3_bucket_versioning resource instead" in Terraform (Terraform)
- Fix "OSError: 'seaborn' is not a valid package style" in Matplotlib (Matplotlib)
- Fix "ImportError: cannot import name 'joblib' from 'sklearn.externals'" (joblib)
- Fix You Must Pass the Application as an Import String to Enable Reload in Uvicorn (Uvicorn)