Skip to content

Cannot pass strings and other types to format() #328

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

Closed
adrian17 opened this issue Feb 5, 2019 · 0 comments
Closed

Cannot pass strings and other types to format() #328

adrian17 opened this issue Feb 5, 2019 · 0 comments

Comments

@adrian17
Copy link
Contributor

adrian17 commented Feb 5, 2019

Self-explanatory:

>>>>> '{}'.format(1)
'1'
>>>>> '{}'.format('1')
Traceback (most recent call last):
  File <unknown>, line 0, in <module>
TypeError: Unsupported method: __format__
>>>>> '{}'.format({})
Traceback (most recent call last):
  File <unknown>, line 0, in <module>
TypeError: Unsupported method: __format__

As for dicts/sets/etc, AFAIK the default object.__format__ simply fallbacks to str() for types without overridden __format__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant