Skip to content

Working with drive objects throws "TypeError: unsupported format string passed to type.__format__" #464

@ebob9

Description

@ebob9

The problem

When working with iCloud Drive objects, the str/type/repr functions throw errors. This apparently is due to the "rf" string complexities. I was able to resolve this by replacing "rf" string line in pyicloud with concatenated standard and "f" strings.

Environment

  • pyiCloud release with the issue (pip show pyicloud):
(.venv) ebob9-mac:icloud_drive_bug_workaround ebob9$ pip show pyicloud
Name: pyicloud
Version: 1.0.0
Summary: PyiCloud is a module which allows pythonistas to interact with iCloud webservices.
Home-page: https://github.com/picklepete/pyicloud
Author: 
Author-email: 
License: MIT
Location: /Users/ebob9/Desktop/longterm_project/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages
Requires: certifi, click, keyring, keyrings.alt, requests, tzlocal
Required-by: 
  • Last working pyiCloud release (if known):
  • Service causing this issue:
    pyicloud DriveNode Class
  • Python version (python -V):
(.venv) ebob9-mac:icloud_drive_bug_workaround ebob9$ python -V
Python 3.12.2
  • Operating environment (project deps/Docker/Windows/etc.):
    MacOS Sequoia w/Python 3.12 (homebrew)

Traceback/Error logs

>>> test1 = api.drive.root
>>> test1
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/ebob9/Desktop/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages/pyicloud/services/drive.py", line 349, in __repr__
    return f"<{type(self).__name__}: {str(self)}>"
                                      ^^^^^^^^^
  File "/Users/ebob9/Desktop/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages/pyicloud/services/drive.py", line 346, in __str__
    return rf"\{type: {self.type}, name: {self.name}\}"
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported format string passed to type.__format__

>>> repr(test1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/ebob9/Desktop/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages/pyicloud/services/drive.py", line 349, in __repr__
    return f"<{type(self).__name__}: {str(self)}>"
                                      ^^^^^^^^^
  File "/Users/ebob9/Desktop/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages/pyicloud/services/drive.py", line 346, in __str__
    return rf"\{type: {self.type}, name: {self.name}\}"
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported format string passed to type.__format__

>>> str(test1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/ebob9/Desktop/pub/icloud_drive_bug_workaround/.venv/lib/python3.12/site-packages/pyicloud/services/drive.py", line 346, in __str__
    return rf"\{type: {self.type}, name: {self.name}\}"
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported format string passed to type.__format__
>>>

Additional information

Will provide a pull request with a simple fix that worked for me shortly after filing this defect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions