mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-76822 Fix dataclass default values in conformance test suite protocols_definition.py
Both mypy and pyright don't show an error for the following case
@dataclass(frozen=False)
class Concrete4_Good7:
val1: Sequence[float] = [0]
However, according to spec, such mutable defaults are not allowed. It will also fail at runtime
(cherry picked from commit ee569653a8f5cf91d6cb87321d63bf8e208d172d)
IJ-MR-174248
GitOrigin-RevId: 275e527ac36ac727dfc23f17bd0b539cff9df8c2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c2ca7adc05
commit
d1cb10773b
@@ -6,7 +6,7 @@ Tests the basic definition rules for protocols.
|
||||
|
||||
from abc import abstractmethod
|
||||
from typing import Any, ClassVar, Iterable, NamedTuple, Protocol, Sequence
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
class SupportsClose(Protocol):
|
||||
@@ -196,7 +196,7 @@ class Concrete4_Good6(NamedTuple):
|
||||
|
||||
@dataclass(frozen=False)
|
||||
class Concrete4_Good7:
|
||||
val1: Sequence[float] = [0]
|
||||
val1: Sequence[float] = field(default_factory=lambda:[0])
|
||||
|
||||
|
||||
class Concrete4_Bad1:
|
||||
@@ -315,7 +315,7 @@ class Concrete6_Good2:
|
||||
|
||||
@dataclass(frozen=False)
|
||||
class Concrete6_Good3:
|
||||
val1: Sequence[float] = [0]
|
||||
val1: Sequence[float] = field(default_factory=lambda:[0])
|
||||
|
||||
|
||||
class Concrete6_Bad1:
|
||||
@@ -330,7 +330,7 @@ class Concrete6_Bad2(NamedTuple):
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Concrete6_Bad3:
|
||||
val1: Sequence[float] = [0]
|
||||
val1: Sequence[float] = field(default_factory=lambda:[0])
|
||||
|
||||
|
||||
v6_good1: Template6 = Concrete6_Good1() # OK
|
||||
|
||||
Reference in New Issue
Block a user