updated from Atlas

This commit is contained in:
Luciano Ramalho
2021-08-07 00:44:01 -03:00
parent cbd13885fc
commit 01e717b60a
96 changed files with 580 additions and 1021 deletions

View File

@@ -1,8 +1,8 @@
import collections
from collections import namedtuple, abc
Card = collections.namedtuple('Card', ['rank', 'suit'])
Card = namedtuple('Card', ['rank', 'suit'])
class FrenchDeck2(collections.MutableSequence):
class FrenchDeck2(abc.MutableSequence):
ranks = [str(n) for n in range(2, 11)] + list('JQKA')
suits = 'spades diamonds clubs hearts'.split()

View File

@@ -12,14 +12,14 @@ class SimplePicker: # <2>
return self._items.pop()
def test_isinstance() -> None: # <4>
popper = SimplePicker([1])
assert isinstance(popper, RandomPicker)
popper: RandomPicker = SimplePicker([1]) # <5>
assert isinstance(popper, RandomPicker) # <6>
def test_item_type() -> None: # <5>
def test_item_type() -> None: # <7>
items = [1, 2]
popper = SimplePicker(items)
item = popper.pick()
assert item in items
if TYPE_CHECKING:
reveal_type(item) # <6>
reveal_type(item) # <8>
assert isinstance(item, int)

View File

@@ -168,5 +168,5 @@ class Vector2d:
@classmethod
def fromcomplex(cls, datum):
return Vector2d(datum.real, datum.imag) # <1>
return cls(datum.real, datum.imag) # <1>
# end::VECTOR2D_V4_COMPLEX[]

View File

@@ -170,5 +170,5 @@ class Vector2d:
@classmethod
def fromcomplex(cls, datum: SupportsComplex) -> Vector2d: # <3>
c = complex(datum) # <4>
return Vector2d(c.real, c.imag)
return cls(c.real, c.imag)
# end::VECTOR2D_V5_COMPLEX[]