Skip to content

Commit

Permalink
Tried to enable strict mode for pyright. Too many missing stubs for t…
Browse files Browse the repository at this point in the history
…hat.
  • Loading branch information
JanEricNitschke committed Oct 31, 2023
1 parent b8c549d commit 9e98417
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions awpy/analytics/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def dist_heuristic(node_a: TileId, node_b: TileId) -> float:
)

try:
geodesic_path = nx.astar_path(
geodesic_path: list[TileId] = nx.astar_path(
map_graph, area_a, area_b, heuristic=dist_heuristic, weight="weight"
)
geodesic_cost = sum(
Expand Down Expand Up @@ -629,7 +629,7 @@ def _get_area_place_mapping(map_name: str) -> dict[str, list[TileId]]:
dict[str, list[TileId]]: The mapping
"areaName": [areas that have this area name] for each "areaName"
"""
area_mapping = defaultdict(list)
area_mapping: dict[str, list[TileId]] = defaultdict(list)
# Get the mapping "areaName": [areas that have this area name]
for area in NAV[map_name]:
area_mapping[NAV[map_name][area]["areaName"]].append(area)
Expand Down
16 changes: 9 additions & 7 deletions awpy/analytics/states.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
"""Functions to generate game stats based on snapshots from a demofile."""
# pylint: disable=unused-argument
from typing import Any

from awpy.types import GameFrame


def generate_vector_state(frame: GameFrame, map_name: str) -> dict:
def generate_vector_state(frame: GameFrame, map_name: str) -> dict[str, Any]:
"""Returns a game state in a dictionary format.
Args:
frame (GameFrame): Dict output of a frame generated from the DemoParser class
map_name (str): String indicating the map name
Returns:
dict: With keys for each feature.
dict[str, Any]: With keys for each feature.
"""
game_state: dict = {
game_state: dict[str, Any] = {
"mapName": map_name,
"secondsSincePhaseStart": frame["seconds"],
"bombPlanted": frame["bombPlanted"],
Expand Down Expand Up @@ -72,27 +74,27 @@ def generate_vector_state(frame: GameFrame, map_name: str) -> dict:
return game_state


def generate_graph_state(frame: GameFrame) -> dict:
def generate_graph_state(frame: GameFrame) -> dict[str, Any]:
"""Returns a game state as a graph.
Args:
frame (GameFrame): Dict output of a frame generated from the DemoParser class
Returns:
dict: With keys "T", "CT" and "Global",
dict[str, Any]: With keys "T", "CT" and "Global",
where each entry is a vector. Global vector is CT + T concatenated
"""
return {"ct": [], "t": [], "global": []}


def generate_set_state(frame: GameFrame) -> dict:
def generate_set_state(frame: GameFrame) -> dict[str, Any]:
"""Returns a game state as a set.
Args:
frame (GameFrame): Dict output of a frame generated from the DemoParser class
Returns:
dict: With keys "T", "CT" and "Global",
dict[str, Any]: With keys "T", "CT" and "Global",
where each entry is a vector. Global vector is CT + T concatenated
"""
return {"ct": [], "t": [], "global": []}
17 changes: 11 additions & 6 deletions awpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@

import re
import subprocess
from typing import Any
from typing import Self, TypeVar

import pandas as pd
from typing_extensions import override

from awpy.types import Area, TileId

_KT = TypeVar("_KT")
_VT = TypeVar("_VT")

class AutoVivification(dict):

class AutoVivification(dict[_KT, _VT | Self]):
"""Implementation of perl's autovivification feature.
Stolen from:
https://stackoverflow.com/questions/651794/whats-the-best-way-to-initialize-a-dict-of-dicts-in-python
"""

def __getitem__(self, item: Any) -> Any: # noqa: ANN401
@override
def __getitem__(self, item: _KT) -> _VT | Self:
"""Autovivified get item from dict.
Tries to get the item as normal.
If a KeyError is encountered another
AutoVivification dict is added instead.
Args:
item (Any): Item to retrieve the value for.
item (_KT): Item to retrieve the value for.
Returns:
Any: Retrieved value.
_VT | Self: Retrieved value.
"""
try:
return dict.__getitem__(self, item)
return dict[_KT, _VT | Self].__getitem__(self, item)
except KeyError:
value = self[item] = type(self)()
return value
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ strictDictionaryInference = true
strictSetInference = true
useLibraryCodeForTypes = false
reportPropertyTypeMismatch = "error"
reportFunctionMemberAccess = "warning"
reportFunctionMemberAccess = "error"
reportMissingTypeStubs = "none"
reportUntypedFunctionDecorator = "error"
reportUntypedClassDecorator = "error"
Expand All @@ -138,14 +138,17 @@ reportUntypedNamedTuple = "error"
reportPrivateUsage = "error"
reportConstantRedefinition = "error"
reportOverlappingOverload = "error"
reportMissingParameterType = "warning"
reportUnnecessaryIsInstance = "none"
reportMissingParameterType = "error"
# Because this is externally visible
# and we want to have the check for users
# that do not use type checkers.
reportUnnecessaryIsInstance = "warning"
reportUnnecessaryCast = "error"
reportUnnecessaryComparison = "error"
reportUnnecessaryContains = "error"
reportAssertAlwaysTrue = "error"
reportUnnecessaryTypeIgnoreComment = "error"
reportImplicitOverride = "none"
reportImplicitOverride = "error"
reportShadowedImports = "error"


Expand Down

0 comments on commit 9e98417

Please sign in to comment.