Skip to content

Commit

Permalink
Skip dataclass doctests in Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio committed Dec 19, 2019
1 parent df5a6d2 commit ea397d3
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -371,24 +371,30 @@ which means you might need to update your existing components

Alternatively, you can use the ``scrapy.utils.decorators.subscriptable_dataclass``
decorator, which adds the appropriate methods in order to make ``dataclass`` objects
capable of being accessed like dictionaries::

>>> from dataclasses import dataclass
>>> from scrapy.utils.decorators import subscriptable_dataclass
>>>
>>> @subscriptable_dataclass
... @dataclass
... class InventoryItem:
... name: str
... price: int
...
>>> d = InventoryItem(name="foobar", price=10)
>>> d["name"]
'foobar'
>>> d["price"] = 5
>>> d
InventoryItem(name='foobar', price=5)
>>>
capable of being accessed like dictionaries:

.. invisible-code-block: python
import sys
.. skip: start if(sys.version_info < (3, 6), reason="python 3.6+ only")
>>> from dataclasses import dataclass
>>> from scrapy.utils.decorators import subscriptable_dataclass
>>> @subscriptable_dataclass
... @dataclass
... class InventoryItem:
... name: str
... price: int
...
>>> d = InventoryItem(name="foobar", price=10)
>>> d["name"]
'foobar'
>>> d["price"] = 5
>>> d
InventoryItem(name='foobar', price=5)

.. skip: end
.. _user agents: https://en.wikipedia.org/wiki/User_agent
Expand Down

0 comments on commit ea397d3

Please sign in to comment.