saghul / aiodns

Simple DNS resolver for asyncio

Home Page:https://pypi.python.org/pypi/aiodns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

query result is wrapped in list: Clarify Readme or change return value

schmittlauch opened this issue · comments

First of all: Thank you for this useful library freeing people from interacting with a C-style interface.

While trying out the given example there is one thing that confuses me: The namedtuple-like query results are wrapped in a single item list:

import asyncio
import aiodns

loop = asyncio.get_event_loop()
resolver = aiodns.DNSResolver(loop=loop)


async def query(name, query_type):
    return await resolver.query(name, query_type)

coro = query('google.com', 'A')
result = loop.run_until_complete(coro)
print(type(result), result)

The code above prints the following using python3.6:
<class 'list'> [ares_query_simple_result(host='172.217.22.110', ttl=151)]

Is this intended? If yes, why? Single-item lists are not really useful, are they?

At least to me this return type wasn't obviuos neither from the aiodns Readme ("The actual result of the DNS query is taken directly from pycares. As of version 1.0.0 of aiodns (and pycares, for that matter) results are always namedtuple-like objects with different attributes") nor from the pycares documentation.

Or am I holding it wrong?

Hi!

First, thanks for the kind words!

Yes, it is intentional. You may get multiple A records for a single query, for instance try amazon.com. Each item on the list represents one of the results.