Fetches an evolution chain from the API.
Parameters: |
-
id_
(int )
–
The name or id of the encounter method.
|
Returns: |
-
EvolutionChain
–
The evolution chain if it exists in the cache, else raises ResourceNotFound.
|
Examples:
Python Console Session>>> from pokelance import PokeLance
>>> import asyncio
>>> client = PokeLance()
>>> async def main() -> None:
... chain = await client.evolution.fetch_evolution_chain(1)
... print(chain.id)
... await client.close()
>>> asyncio.run(main())
1
Source code in pokelance/ext/evolution.py
Python |
---|
| async def fetch_evolution_chain(self, id_: int) -> EvolutionChain:
"""Fetches an evolution chain from the API.
Parameters
----------
id_: int
The name or id of the encounter method.
Returns
-------
EvolutionChain
The evolution chain if it exists in the cache, else raises ResourceNotFound.
Raises
------
pokelance.exceptions.ResourceNotFound
The name or id of the evolution chain is invalid.
Examples
--------
>>> from pokelance import PokeLance
>>> import asyncio
>>> client = PokeLance()
>>> async def main() -> None:
... chain = await client.evolution.fetch_evolution_chain(1)
... print(chain.id)
... await client.close()
>>> asyncio.run(main())
1
"""
route = Endpoint.get_evolution_chain(id_)
self._validate_resource(self.cache.evolution_chain, id_, route)
data = await self._client.request(route)
return self.cache.evolution_chain.setdefault(route, EvolutionChain.from_payload(data))
|