{"action":"created","issue":{"url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/202","repository_url":"https://api.github.com/repos/jandecaluwe/myhdl","labels_url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/202/labels{/name}","comments_url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/202/comments","events_url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/202/events","html_url":"https://github.com/jandecaluwe/myhdl/issues/202","id":188227663,"number":202,"title":"Exception printing intbv/modbv with Python3","user":{"login":"MarioSchwalbe","id":22843211,"avatar_url":"https://avatars.githubusercontent.com/u/22843211?v=3","gravatar_id":"","url":"https://api.github.com/users/MarioSchwalbe","html_url":"https://github.com/MarioSchwalbe","followers_url":"https://api.github.com/users/MarioSchwalbe/followers","following_url":"https://api.github.com/users/MarioSchwalbe/following{/other_user}","gists_url":"https://api.github.com/users/MarioSchwalbe/gists{/gist_id}","starred_url":"https://api.github.com/users/MarioSchwalbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarioSchwalbe/subscriptions","organizations_url":"https://api.github.com/users/MarioSchwalbe/orgs","repos_url":"https://api.github.com/users/MarioSchwalbe/repos","events_url":"https://api.github.com/users/MarioSchwalbe/events{/privacy}","received_events_url":"https://api.github.com/users/MarioSchwalbe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-09T11:43:38Z","updated_at":"2016-11-09T13:26:52Z","closed_at":null,"body":"Hi,\r\n\r\nI've found another minor Python3 inconsistency. The following code works with Python 2 but fails with Python 3. This is MyHDL 1.0dev:\r\n```python\r\nfrom __future__ import print_function\r\nfrom myhdl import intbv\r\n\r\nimport sys\r\n\r\nx = intbv(10)\r\n\r\nprint(\"{}\".format(x))\r\nif sys.version_info.major >= 3:\r\n    print(\"{!a:>20}\".format(x))\r\nprint(\"{!r:>20}\".format(x))\r\nprint(\"{!s:>20}\".format(x))\r\n# Fails with Python3\r\nprint(\"{:>20}\".format(x))\r\n```\r\nThe last one raises:\r\n```\r\n$ python3 FormatBug.py\r\na\r\n           intbv(10)\r\n           intbv(10)\r\n                   a\r\nTraceback (most recent call last):\r\n  File \"FormatBug.py\", line 20, in <module>\r\n    print(\"{:>20}\".format(x))\r\nTypeError: non-empty format string passed to object.__format__\r\n```\r\nThe same happens for `modbv` or `Signal` instances if one of the custom integer types is being used."},"comment":{"url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/comments/259413980","html_url":"https://github.com/jandecaluwe/myhdl/issues/202#issuecomment-259413980","issue_url":"https://api.github.com/repos/jandecaluwe/myhdl/issues/202","id":259413980,"user":{"login":"MarioSchwalbe","id":22843211,"avatar_url":"https://avatars.githubusercontent.com/u/22843211?v=3","gravatar_id":"","url":"https://api.github.com/users/MarioSchwalbe","html_url":"https://github.com/MarioSchwalbe","followers_url":"https://api.github.com/users/MarioSchwalbe/followers","following_url":"https://api.github.com/users/MarioSchwalbe/following{/other_user}","gists_url":"https://api.github.com/users/MarioSchwalbe/gists{/gist_id}","starred_url":"https://api.github.com/users/MarioSchwalbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarioSchwalbe/subscriptions","organizations_url":"https://api.github.com/users/MarioSchwalbe/orgs","repos_url":"https://api.github.com/users/MarioSchwalbe/repos","events_url":"https://api.github.com/users/MarioSchwalbe/events{/privacy}","received_events_url":"https://api.github.com/users/MarioSchwalbe/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T13:26:52Z","updated_at":"2016-11-09T13:26:52Z","body":"Oh, did not know that before. From the python docs:\r\n> The conversion field causes a type coercion before formatting. Normally, the job of formatting a value is done by the __format__() method of the value itself. However, in some cases it is desirable to force a type to be formatted as a string, overriding its own definition of formatting. By converting the value to a string before calling __format__(), the normal formatting logic is bypassed.\r\n\r\nWhat I get here is: With no conversion specification `__format__` gets used to print a python object according to its own understanding of formatting. Right? So, (a) since, `int`s can be formatted, it should also work for `intbv`, and (b) would be backwards-compatible. Both would be less confusing for newcomers. If it's not too complicated to implement...\r\n\r\nBut also not a big deal, as I usually convert to `int` anyway to get the decimal representation, rather than hexadecimal, which seems to be the new default in 1.0dev."}}
{"actor":{"display_login":"MarioSchwalbe"}}