Skip to content

Commit 74007f6

Browse files
ClassBuilder: eval only once (#1407)
* ClassBuilder: eval only once * avoid Attribute.evolve * speed up `_make_attr_tuple_class` * speed up `_add_method_dunders` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * optimize _CountingAttrs more * Fix up `_add_method_dunders` * avoid a hot splitlines * restore old type_hash * fix scriptlines handling * restore contextlib.suppress * Revert "fix scriptlines handling" This reverts commit 4e0af4b. * Revert "avoid a hot splitlines" This reverts commit 532faed. * add some hints * fix tests * Refactor `_Attributes` * Reflow * Reflow docs * Microoptimization * Rework type hints a little * Fix arg name * Add changelog entry --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e048efc commit 74007f6

File tree

6 files changed

+279
-204
lines changed

6 files changed

+279
-204
lines changed

changelog.d/1407.change.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up class creation by 30%-50% by compiling methods only once and using a variety of other techniques.

src/attr/_cmp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import functools
55
import types
66

7-
from ._make import _make_ne
7+
from ._make import __ne__
88

99

1010
_operation_names = {"eq": "==", "lt": "<", "le": "<=", "gt": ">", "ge": ">="}
@@ -71,7 +71,7 @@ def cmp_using(
7171
if eq is not None:
7272
has_eq_function = True
7373
body["__eq__"] = _make_operator("eq", eq)
74-
body["__ne__"] = _make_ne()
74+
body["__ne__"] = __ne__
7575

7676
if lt is not None:
7777
num_order_functions += 1

0 commit comments

Comments
 (0)