Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrect type reported by type checker for async properties #63

Closed
@ValdezFOmar

Description

@ValdezFOmar

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.

import sdbus
import sdbus_async.networkmanager as nm
from typing import reveal_type

system_bus = sdbus.sd_bus_open_system()

async def get_wifi_connections(wifi_device: nm.NetworkDeviceWireless):
    for path in await wifi_device.get_all_access_points():
        access_point = nm.AccessPoint(path, system_bus)
        ssid = await access_point.ssid
        reveal_type(ssid)
        ssid = await access_point.ssid.get_async()
  reveal_type(ssid)

mypy output:

$ mypy type_test_async.py
type_test_async.py:10: error: Need type annotation for "ssid"  [var-annotated]
type_test_async.py:11: note: Revealed type is "Any"
type_test_async.py:13: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)

pyright output:

$ pyright type_test_async.py
./type_test_async.py
 ./type_test_async.py:11:21 - information: Type of "ssid" is "T@__await__"
 ./type_test_async.py:13:21 - information: Type of "ssid" is "Unknown"
0 errors, 0 warnings, 2 informations 

In 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.

import sdbus
import sdbus_block.networkmanager as nm_block
from typing import reveal_type

system_bus = sdbus.sd_bus_open_system()

def get_wifi_block_connections(wifi_device: nm_block.NetworkDeviceWireless):
    for path in wifi_device.access_points:
        access_point = nm_block.AccessPoint(path, system_bus)
        ssid = access_point.ssid
        reveal_type(ssid)  # Both mypy and pyright report `bytes`

I'm using:

  • mypy 1.8.0
  • pyright 1.1.350
  • python 3.11.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions