0

Question : In the below code snippet I want to assign the type to source_sol and target_sol args in the function move. What type should I assign it to be ?

class Solution:
    def __init__(self):
        self.hamming_loss = 0
        self.active_features = []
        self.rank = None
        self.pareto_solution = True

    def move(self, source_sol, target_sol) -> None:
        return None

    def __str__(self) -> str:
        return None

source_sol = Solution()
target_sol = Soltuion()
new_sol = Solution()
new_sol.move(source_sol, target_sol)
Chris
  • 26,361
  • 5
  • 21
  • 42
black sheep 369
  • 564
  • 8
  • 19
  • Note: you appear to have a typo: `target_sol = Soltuion()` is doubtless meant to be `target_sol = Solution()` – Chris Feb 01 '22 at 06:18
  • 2
    Do you mean "annotate"? Like `def move(self, source: Solution, target: Solution) -> None:` which will require a `from __future__ import annotations`. – matheburg Feb 01 '22 at 06:18
  • 1
    Maybe, one point to improve your quality of questions in future: make the example you give minimal (why this longish `__init__` and the `__str__` w/o relevance for the question?). – matheburg Feb 01 '22 at 06:25
  • *classes are types in Python* – juanpa.arrivillaga Feb 01 '22 at 07:04

0 Answers0