Bug#1115253: python3-apt: apt_pkg.MetaIndex does not document nor type the 'type' property
Package: python3-apt
Version: 3.0.0
Severity: normal
Hi,
While writing python scripts with apt_pkg, I discovered (by chance) that the
apt_pkg.MetaIndex provides a 'type' property. It is important because the
triplet (type, uri, dist) uniquely identify the MetaIndex (and the triplet
is the only way I found to link the apt_pkg.MetaIndex to the
aptsources.sourceslist.SourcesList sub objects)
https://apt-team.pages.debian.net/python-apt/library/apt_pkg.html#apt_pkg.MetaIndex
does not talk about the 'type' property.
It is not present in /usr/lib/python3/dist-packages/apt_pkg-stubs/__init__.pyi:
[...]
class MetaIndex:
dist: str
index_files: List[IndexFile]
is_trusted: bool
uri: str
class SourceList:
[...]
However, the property exists as shown by the following program:
$ cat /tmp/test.py
import apt_pkg
apt_pkg.init()
sources = apt_pkg.SourceList()
sources.read_main_list()
for source in sources.list:
print(f'MetaIndex {source.type} {source.uri} {source.dist}')
The property always returns "deb" (I got no "deb-src" even if I have some in my
sources.list.d/* files). And type checkers complain about this property:
$ mypy /tmp/test.py
/tmp/test.py:8: error: "MetaIndex" has no attribute "type" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
$ pyright /tmp/test.py
/tmp/test.py
/tmp/test.py:8:31 - error: Cannot access attribute "type" for class "MetaIndex"
Attribute "type" is unknown (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations
As the property exists, it should probably be added to the documentation and
python hint type file (but as it always has "deb", I'm not so sure it is
really useful in fact)
Working on deb sources, I just saw while writing this bug report that
apt_pkg.IndexFile are linked to the same apt_pkg.MetaIndex object
independently of its type (and the MetaIndex always reports "deb"
as said before). The kind of IndexFile seems discoverable with
the label property. The documentation should list acceptable
values ('Debian Package Index', 'Debian Source Index' and
'Debian Translation Index' it seems)
If we want to link back apt_pkg.IndexFile to
aptsources.sourceslist.SourcesList().exploded_list()
it will be more difficult if we want to handle "deb-src" type.
Note that even the triplet (type, uri, dist) [for type="deb"]
needs workaround as uri can be rewritten in apt_pkg.MetaIndex
(a final '/' can be added)
Regards
Vincent
-- System Information:
Debian Release: forky/sid
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'oldstable-updates'), (500, 'oldstable-security'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (500, 'oldstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armel
Kernel: Linux 6.12.41+deb13-amd64 (SMP w/4 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE
Locale: LANG=fr_FR.utf8, LC_CTYPE=fr_FR.utf8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages python3-apt depends on:
ii distro-info-data 0.66
ii libapt-pkg7.0 3.1.4
ii libc6 2.41-12
ii libgcc-s1 15.2.0-1
ii libstdc++6 15.2.0-1
ii python-apt-common 3.0.0
ii python3 3.13.5-1
Versions of packages python3-apt recommends:
ii iso-codes 4.18.0-1
ii lsb-release 12.1-1
Versions of packages python3-apt suggests:
ii apt 3.1.4
pn python-apt-doc <none>
-- no debconf information
Reply to: