TypeError with Move data - Must be mapping not nulltype
criiptico opened this issue · 5 comments
Describe the bug
I get a TypeError when after using using move_data = await client.get_move(int(move))
iteratively 9 times.
Expected behavior
Expected to iterate through a list of n ids and retrieve the move data from aiopokeapi client from an id from a list of ids.
To Reproduce
Steps to reproduce the behavior:
- Construct of list of move ids
- Inside a function, use
async with aiopoke.AiopokeClient() as client:
, - Then, iterate the list of ids and populate a dict in this format: [id] = move_name, where the move_name is received from the aiopokeapi (i.e. move = client.get_move(id), then move_name = move.name).
Here is the code that caused the issue:
async def __load_moves(self, pokemon: Pokemon, pokemon_data):
async with aiopoke.AiopokeClient() as client:
moves_id = self.__get_move_ids(pokemon_data) # get the move ids first (returns a list)
print(moves_id)
# Use client to load the pokemon with its corresponding move_name, move_id, and move_power | Load it in the Pokemon type data member: moves = {}
for move in moves_id:
move_data = await client.get_move(int(move)) # Error on line 21
new_move = Move() # Imported Move class
new_move.id = move
new_move.name = move_data.name
new_move.power = move_data.power
new_move.type = move_data.type
pokemon.moves[move_data.name] = new_move
print(move_data.name)
Error Message
python3 pokeType_main.py < ../resources/input.txt > ../resources/output
Traceback (most recent call last):
File "/home/adrian/projects/poketype/prototype/main/pokeType_main.py", line 54, in <module>
asyncio.run(main())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/adrian/projects/poketype/prototype/main/pokeType_main.py", line 42, in main
await load_poke_data.load_pokemon(pokemon_1, pokemon_1_data)
File "/home/adrian/projects/poketype/prototype/main/Load_Pokemon_Data.py", line 51, in load_pokemon
await self.__load_moves(pokemon, pokemon_data)
File "/home/adrian/projects/poketype/prototype/main/Load_Pokemon_Data.py", line 21, in __load_moves
move_data = await client.get_move(int(move)) # API Wrapper Error on line 23
File "/home/adrian/projects/virtualEnvironments/pokeTypeVenv/lib/python3.10/site-packages/aiopoke/utils/cache.py", line 27, in wrapper
obj: U = await coro(client, name_or_id)
File "/home/adrian/projects/virtualEnvironments/pokeTypeVenv/lib/python3.10/site-packages/aiopoke/aiopoke_client.py", line 200, in get_move
return Move(**data)
File "/home/adrian/projects/virtualEnvironments/pokeTypeVenv/lib/python3.10/site-packages/aiopoke/objects/resources/moves/move.py", line 114, in __init__
self.past_values = [
File "/home/adrian/projects/virtualEnvironments/pokeTypeVenv/lib/python3.10/site-packages/aiopoke/objects/resources/moves/move.py", line 115, in <listcomp>
PastMoveStatValues(**past_value) for past_value in past_values
File "/home/adrian/projects/virtualEnvironments/pokeTypeVenv/lib/python3.10/site-packages/aiopoke/objects/resources/moves/move.py", line 266, in __init__
self.type = MinimalResource(**type)
TypeError: aiopoke.utils.minimal_resources.MinimalResource() argument after ** must be a mapping, not NoneType
Desktop (please complete the following information):
- OS: Windows 11
- Python Version: 3.10.6
- Aiopokeapi Version: 0.1.7
Additional context
I'm working on the same project I worked on before which can be found here. The specific file where this error occurred is here in line 21.
Seems pretty strange, docs say it can't be null type. Anyways, I fixed it in commit 23aee50.
Make sure you pull the latest version from Github, I will release a new version as soon as aiohttp support python 3.12.
I've pulled the latest version but I'm still getting this error. I've also made sure to double check I'm using the latest version of this package which included the fix PastMoveStatValues(**past_value) for past_value in past_values if past_value is not None
for this issue.
Here is the error I'm getting after updating:
(pokeTypeVenv) adrian@Adrian:~/projects/poketype/prototype/main$ make io
python3 pokeType_main.py < ../resources/input.txt > ../output/output.txt
Traceback (most recent call last):
File "/home/adrian/projects/poketype/prototype/main/pokeType_main.py", line 66, in <module>
asyncio.run(main())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/adrian/projects/poketype/prototype/main/pokeType_main.py", line 54, in main
await load_poke_data.load_pokemon(pokemon_1, pokemon_1_data)
File "/home/adrian/projects/poketype/prototype/main/Load_Pokemon_Data.py", line 67, in load_pokemon
await self.__load_moves(pokemon, pokemon_data)
File "/home/adrian/projects/poketype/prototype/main/Load_Pokemon_Data.py", line 37, in __load_moves
move_data = await client.get_move(int(move)) # Error on line 37
File "/home/adrian/projects/poketype/prototype/aiopokeapi/src/aiopoke/utils/cache.py", line 27, in wrapper
obj: U = await coro(client, name_or_id)
File "/home/adrian/projects/poketype/prototype/aiopokeapi/src/aiopoke/aiopoke_client.py", line 200, in get_move
return Move(**data)
File "/home/adrian/projects/poketype/prototype/aiopokeapi/src/aiopoke/objects/resources/moves/move.py", line 114, in __init__
self.past_values = [
File "/home/adrian/projects/poketype/prototype/aiopokeapi/src/aiopoke/objects/resources/moves/move.py", line 115, in <listcomp>
PastMoveStatValues(**past_value) for past_value in past_values if past_value is not None
File "/home/adrian/projects/poketype/prototype/aiopokeapi/src/aiopoke/objects/resources/moves/move.py", line 266, in __init__
self.type = MinimalResource(**type)
TypeError: aiopoke.utils.minimal_resources.MinimalResource() argument after ** must be a mapping, not NoneType
make: *** [makefile:14: io] Error 1
Are you sure that shouldn't be possible, you must install it via github. Try this:
pip install "git+https://github.com/beastmatser/aiopokeapi.git"
I've tried it that way but I I get the same error. Beforehand I've also tried git clone https://github.com/beastmatser/aiopokeapi.git
, followed by python setup.py develop
, but I still get the error.
On the same issue, as I was trying to debug this further, I was able to reproduce this in another system and discovered that this TypeError exception happens to only some move ids. The way I reproduced this in my other system was by installing the package as you suggested and then tried the ids that worked and ids that threw the exception.
Here is a link of an output displaying the ids that work and those that don't.