Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type hints around a bit #25

Merged
merged 1 commit into from
Jan 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/debaterpy/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DebaterJSON."""
from __future__ import annotations
import json
from typing import Optional
from typing import Optional, Self
from datetime import datetime, date
from dataclasses import dataclass

Expand Down Expand Up @@ -30,12 +30,12 @@ def to_json(self) -> str:
return json.dumps(dict(self))

@classmethod
def from_json(cls, data: str) -> Item:
def from_json(cls, data: str) -> Self:
"""Instantiates a new object based on the data contained in the json string ``data``."""
return cls.from_dict(json.loads(data))

@classmethod
def from_dict(self, data: dict) -> Item:
def from_dict(self, data: dict) -> Self:
"""instantiate a new object based on the dictionary ``data``. """
raise NotImplementedError

Expand All @@ -49,7 +49,7 @@ class Record(Item):
"""The name of the speaker in this account."""

@classmethod
def from_dict(cls, data: dict) -> Record:
def from_dict(cls, data: dict) -> Self:
return cls(
tournaments=[Tournament.from_dict(tournament) for tournament in data["tournaments"]],
speaker_name=data.get("speaker_name")
Expand All @@ -71,7 +71,7 @@ class Tournament(Item):
"""All the rounds the debater participated in in this tournament."""

@classmethod
def from_dict(cls, data: dict) -> Tournament:
def from_dict(cls, data: dict) -> Self:
return cls(
tournament_name=data["tournament_name"],
format=data.get("format"),
Expand Down Expand Up @@ -117,7 +117,7 @@ class Round(Item):
"""If the speaker advanced to the next phase of the tournament (if this round is an outround)."""

@classmethod
def from_dict(cls, data: dict) -> Round:
def from_dict(cls, data: dict) -> Self:
if "speech" in data.keys() or "speak" in data.keys(): # neccesary due to these attributes' deprecation
speeches = [Speech(data.get("speech"), data.get("speak"))]
else:
Expand Down Expand Up @@ -151,7 +151,7 @@ class Speech(Item):
"""The speak this speech received."""

@classmethod
def from_dict(cls, data: dict) -> Speech:
def from_dict(cls, data: dict) -> Self:
return cls(
speech=data.get("speech"),
speak=data.get("speak")
Expand Down