Python 3.9 compatibility
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
import typing
|
||||
|
||||
import sys
|
||||
|
||||
def attributes_in_class():
|
||||
class Pet:
|
||||
@@ -46,15 +46,16 @@ def attributes_in_dataclass():
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
|
||||
def attributes_in_dataclass_with_slots():
|
||||
@dataclass(slots=True)
|
||||
class Pet:
|
||||
legs: int
|
||||
noise: str
|
||||
if sys.version_info.minor >= 10:
|
||||
def attributes_in_dataclass_with_slots():
|
||||
@dataclass(slots=True)
|
||||
class Pet:
|
||||
legs: int
|
||||
noise: str
|
||||
|
||||
for _ in range(100000):
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
for _ in range(100000):
|
||||
dog = Pet(4, "woof")
|
||||
str(dog)
|
||||
|
||||
def attributes_in_namedtuple():
|
||||
Pet = namedtuple("Pet", "legs noise")
|
||||
@@ -78,10 +79,12 @@ def attributes_in_dict():
|
||||
|
||||
__benchmarks__ = [
|
||||
(attributes_in_dataclass, attributes_in_class, "Class instead of dataclass"),
|
||||
(attributes_in_dataclass, attributes_in_dataclass_with_slots, "dataclass with slots"),
|
||||
(attributes_in_dataclass, attributes_in_namedtuple, "Namedtuple instead of dataclass"),
|
||||
(attributes_in_namedtuple, attributes_in_class, "class instead of namedtuple"),
|
||||
(attributes_in_namedtuple, attributes_in_namedtuple_type, "namedtuple class instead of namedtuple"),
|
||||
(attributes_in_class, attributes_in_dict, "dict instead of class"),
|
||||
(attributes_in_class, attributes_in_class_with_slots, "class with slots"),
|
||||
(attributes_in_class, attributes_in_class_with_slots, "class with slots")
|
||||
]
|
||||
if sys.version_info.minor >= 10:
|
||||
__benchmarks__.append((attributes_in_dataclass, attributes_in_dataclass_with_slots, "dataclass with slots"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user