Title: Incorrect type reported by type checker for async properties · Issue #63 · python-sdbus/python-sdbus-networkmanager · GitHub
Open Graph Title: Incorrect type reported by type checker for async properties · Issue #63 · python-sdbus/python-sdbus-networkmanager
X Title: Incorrect type reported by type checker for async properties · Issue #63 · python-sdbus/python-sdbus-networkmanager
Description: When trying to access an async property of an interface, both mypy and pyright report the wrong type. In this example, I'd expect access_point.ssid to report type bytes, but it doesn't. Also, if I call get_async() directly it reports a d...
Open Graph Description: When trying to access an async property of an interface, both mypy and pyright report the wrong type. In this example, I'd expect access_point.ssid to report type bytes, but it doesn't. Also, if I ...
X Description: When trying to access an async property of an interface, both mypy and pyright report the wrong type. In this example, I'd expect access_point.ssid to report type bytes, but it doesn't. Als...
Opengraph URL: https://github.com/python-sdbus/python-sdbus-networkmanager/issues/63
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect type reported by type checker for async properties","articleBody":"When trying to access an async property of an interface, both **mypy** and **pyright** report the wrong type. In this example, I'd expect `access_point.ssid` to report type `bytes`, but it doesn't. Also, if I call `get_async()` directly it reports a different type for pyright.\r\n\r\n```py\r\nimport sdbus\r\nimport sdbus_async.networkmanager as nm\r\nfrom typing import reveal_type\r\n\r\nsystem_bus = sdbus.sd_bus_open_system()\r\n\r\nasync def get_wifi_connections(wifi_device: nm.NetworkDeviceWireless):\r\n for path in await wifi_device.get_all_access_points():\r\n access_point = nm.AccessPoint(path, system_bus)\r\n ssid = await access_point.ssid\r\n reveal_type(ssid)\r\n ssid = await access_point.ssid.get_async()\r\n reveal_type(ssid)\r\n```\r\n\r\nmypy output:\r\n\r\n```\r\n$ mypy type_test_async.py\r\ntype_test_async.py:10: error: Need type annotation for \"ssid\" [var-annotated]\r\ntype_test_async.py:11: note: Revealed type is \"Any\"\r\ntype_test_async.py:13: note: Revealed type is \"Any\"\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\npyright output:\r\n\r\n ```\r\n$ pyright type_test_async.py\r\n./type_test_async.py\r\n ./type_test_async.py:11:21 - information: Type of \"ssid\" is \"T@__await__\"\r\n ./type_test_async.py:13:21 - information: Type of \"ssid\" is \"Unknown\"\r\n0 errors, 0 warnings, 2 informations \r\n ```\r\n\r\n\r\nIn both cases, I would expect for the revealed type to be `bytes`. At runtime, my code works and `reveal_type` prints `Runtime type is 'bytes'`, so I guess the problem has to do with the type hints. Also, the blocking API doesn't have this problem and correctly report `bytes`.\r\n\r\n```py\r\nimport sdbus\r\nimport sdbus_block.networkmanager as nm_block\r\nfrom typing import reveal_type\r\n\r\nsystem_bus = sdbus.sd_bus_open_system()\r\n\r\ndef get_wifi_block_connections(wifi_device: nm_block.NetworkDeviceWireless):\r\n for path in wifi_device.access_points:\r\n access_point = nm_block.AccessPoint(path, system_bus)\r\n ssid = access_point.ssid\r\n reveal_type(ssid) # Both mypy and pyright report `bytes`\r\n```\r\n\r\nI'm using:\r\n- mypy 1.8.0\r\n- pyright 1.1.350\r\n- python 3.11.7\r\n","author":{"url":"https://github.com/ValdezFOmar","@type":"Person","name":"ValdezFOmar"},"datePublished":"2024-02-15T09:25:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/63/python-sdbus-networkmanager/issues/63"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4085cf27-5bd4-7d9d-ac05-ed5a22694f03 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99A8:36A8E0:D29B41:115433C:698D7046 |
| html-safe-nonce | 0c065f1d19c1d3a166b263df093d18365bfd8c684021364ae563fea061b363a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUE4OjM2QThFMDpEMjlCNDE6MTE1NDMzQzo2OThENzA0NiIsInZpc2l0b3JfaWQiOiI0OTkxMTQzODAyNTc3NTExMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1996fb36f1259de6e5c6067bd197656ad951ffd1620282a8b91b38224e524dd6 |
| hovercard-subject-tag | issue:2136042232 |
| github-keyboard-shortcuts | repository,issues,network-graph,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-sdbus/python-sdbus-networkmanager/63/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5271d7332bb3d0d37f30b805127bc9180d3192870c9e26d20ade59e22c2a8441/python-sdbus/python-sdbus-networkmanager/issues/63 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5271d7332bb3d0d37f30b805127bc9180d3192870c9e26d20ade59e22c2a8441/python-sdbus/python-sdbus-networkmanager/issues/63 |
| og:image:alt | When trying to access an async property of an interface, both mypy and pyright report the wrong type. In this example, I'd expect access_point.ssid to report type bytes, but it doesn't. Also, if I ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ValdezFOmar |
| hostname | github.com |
| expected-hostname | github.com |
| None | c0818105fa276287e9369cfdefa0a0fa7953719791ceff9b94d69623c0a4fe8a |
| turbo-cache-control | no-preview |
| go-import | github.com/python-sdbus/python-sdbus-networkmanager git https://github.com/python-sdbus/python-sdbus-networkmanager.git |
| octolytics-dimension-user_id | 88226657 |
| octolytics-dimension-user_login | python-sdbus |
| octolytics-dimension-repository_id | 384529652 |
| octolytics-dimension-repository_nwo | python-sdbus/python-sdbus-networkmanager |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 384529652 |
| octolytics-dimension-repository_network_root_nwo | python-sdbus/python-sdbus-networkmanager |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 715890fa442134f528fb422ab338c0ad55c7a025 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width