Comments (3)
The mypy
documentation that I linked to provided several different approaches. I don't have any additional suggestions beyond those. For GeoIP2 or GeoLite2 databases, we provide the geoip2
package that has structured model classes for each database type. However, it appears you are using a competitor's database, which I believe has a different internal layout.
from maxmind-db-reader-python.
As the return type suggests, a get
call can return may different types depending on the particular database being used. Please see the mypy
documentation on type narrowing.
from maxmind-db-reader-python.
@oschwald I'm familiar w/ type narrowing, but the way I'm getting it to work for this looks incredibly hacky:
def ipinfo_db_lookup(ip_address: str) -> dict | None:
with maxminddb.open_database(ipinfo_db_path) as reader:
ip_record = reader.get(ip_address)
assert isinstance(ip_record, dict | type(None))
# could also be:
# assert isinstance(ip_record, dict) or ip_record is None
return ip_record
Is there a more graceful way of tackling this?
from maxmind-db-reader-python.
Related Issues (20)
- Reading Multiple MMDB Files HOT 1
- Python `whl` releases HOT 1
- Iterating over the whole database is broken HOT 3
- TypeError: 'Reader' object is not iterable HOT 1
- PyPI sdist tarball no longer contains tests/data folder HOT 2
- test failures in Python 3.7 HOT 2
- City name is none HOT 1
- Type hints for mypy HOT 8
- Allow accessing the network field in the ASN mmdb file HOT 4
- Null pointer dereference with corrupt database file in MODE_MMAP_EXT HOT 2
- PyPI tarball - some test data missing HOT 3
- "MODE_MMAP_EXT requires the maxminddb.extension module to be available" though libmaxminddb is installed HOT 8
- The GH releases have no test db HOT 3
- ValueError: Unsupported open mode: MODE_MMAP_EXT HOT 1
- Performance variance between python versions HOT 1
- New version is breaking Python 2 installs - missing setup.py python_requires update HOT 3
- Use ipv4 and ipv6 geographic libraries to generate mmdb files HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Running in an environment without mmap? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maxmind-db-reader-python.