systemd / pystemd

A thin Cython-based wrapper on top of libsystemd, focused on exposing the dbus API via sd-bus in an automated and easy to consume way.
GNU Lesser General Public License v2.1
414 stars 36 forks source link

Mypy #missing-imports not picking up typehints #94

Closed guywilsonjr closed 2 weeks ago

guywilsonjr commented 2 months ago

I'm looking for a little guidance on type checking with mypy. I'm not sure why but I always get errors when using pystemd.

Tested on: /etc/os-release

NAME="Linux Mint"
VERSION="21.1 (Vera)"
ID=linuxmint
ID_LIKE="ubuntu debian"
PRETTY_NAME="Linux Mint 21.1"
VERSION_ID="21.1"
HOME_URL="https://www.linuxmint.com/"
SUPPORT_URL="https://forums.linuxmint.com/"
BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
PRIVACY_POLICY_URL="https://www.linuxmint.com/"
VERSION_CODENAME=vera
UBUNTU_CODENAME=jammy

Using:

Steps to reproduce:

python3 -m venv venv
venv/bin/pip install mypy pystemd
echo "import pystemd" >> example_pystemd.py
venv/bin/mypy example_pystemd.py

Mypy Output:

example_pystemd.py:1: error: Skipping analyzing "pystemd": module is installed, but missing library stubs or py.typed marker  [import-untyped]
example_pystemd.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Am I doing something wrong? Is mypy doing something wrong? or does this package not fully support typehints?

guywilsonjr commented 2 months ago

FWIW According to https://github.com/python/typing/issues/1333 we might simply need an empty py.typed file in the pystemd folder. I cloned and tested this locally and it seems to work