pylint fails to detect geoip2.records.Country.iso_code field

Bug #1941625 reported by Vasily Zakharov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-geoip2 (Ubuntu)
New
Undecided
Unassigned

Bug Description

Ubuntu 20.04.3 LTS
python3-geoip2: 2.9.0+dfsg1-2

The following code:

from geoip2.database import Reader
reader = Reader('/var/lib/GeoIP/GeoLite2-City.mmdb')
response = reader.city('8.8.8.8')
country = response.country
print(type(country), country.iso_code)

produces the following output:

$ python3 test.py
<class 'geoip2.records.Country'> US
$ pylint test.py
************* Module test
test.py:5: [E1101(no-member), ] Instance of 'Country' has no 'iso_code' member
$ pylint --version
pylint 2.10.2
astroid 2.7.2
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0]

As you can see, the `iso_code` field is definitely there, but for some reason `pylint` doesn't see it.

One potential reason for this maybe that `Country` class `__name__` doesn't include a package name:

$ python3
Python 3.8.10 (default, Jun 2 2021, 10:49:15)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from geoip2.records import Country
>>> Country.__name__
'Country'

Another potential reason may be confusion between `geoip2.records.Country` and `geoip2.models.Country` that has no such field.

The problem does not appear if recent version of `geoip2` is installed from `pip`, so probably updating the code in Ubuntu package to recent version would help.

See also https://github.com/PyCQA/pylint/issues/4911.

description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.