Skip to content

Commit b24df9e

Browse files
committed
Fixes for more issues uncovered by PyPy.
* Exceptions: Ensure that attributes which are mutated by the PyPy runtime are actually mutable. * Classes: Ensure that protocol classes (descendents of ABC) allow their ABC machinery to be mutated after initialization. PyPy performs replacement on internally-mutable collections rather than clearing and repopulating them. Also, * Exceptions: Expose common constants for mutable and visible attributes so that they can be reused downstream. * Nomina: Expose 'is_public_identifier' for reuse downstream.
1 parent 5061ca1 commit b24df9e

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

sources/classcore/exceptions.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@
2222

2323

2424
from . import __
25+
from . import nomina as _nomina
2526
from . import standard as _standard
2627

2728

29+
exception_mutables_default = (
30+
'__cause__', '__context__', '__suppress_context__', '__traceback__' )
31+
exception_visibles_default = (
32+
*exception_mutables_default, _nomina.is_public_identifier )
33+
34+
2835
class Omniexception(
2936
_standard.Object, BaseException,
30-
instances_visibles = ( '__cause__', '__context__' ),
37+
instances_mutables = exception_mutables_default,
38+
instances_visibles = exception_visibles_default,
3139
):
3240
''' Base exception for package. '''
3341

sources/classcore/nomina.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,8 @@
204204
],
205205
__.ddoc.Doc( ''' Initializer to use with metaclass. ''' ),
206206
]
207+
208+
209+
def is_public_identifier( name: str ) -> bool:
210+
''' Is Python identifier public? '''
211+
return not name.startswith( '_' )

sources/classcore/standard/__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020

2121
''' Common constants, imports, and utilities. '''
2222

23+
# ruff: noqa: F403
2324

24-
from ..__ import * # noqa: F403
2525

26-
27-
def is_public_identifier( name: str ) -> bool:
28-
''' Is Python identifier public? '''
29-
return not name.startswith( '_' )
26+
from ..__ import *
27+
from ..nomina import is_public_identifier
3028

3129

3230
def provide_error_class( name: str ) -> type[ Exception ]:

sources/classcore/standard/classes.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,16 @@ class DataclassObjectMutable( metaclass = DataclassMutable ):
205205
'class instance conceal' )
206206

207207

208-
class Protocol( __.typx.Protocol, metaclass = ProtocolClass ):
208+
class Protocol(
209+
__.typx.Protocol,
210+
metaclass = ProtocolClass,
211+
class_mutables = (
212+
'_abc_cache',
213+
'_abc_negative_cache',
214+
'_abc_negative_cache_version',
215+
'_abc_registry',
216+
),
217+
):
209218
''' Standard base protocol class. '''
210219

211220
_dynadoc_fragments_ = (
@@ -215,7 +224,15 @@ class Protocol( __.typx.Protocol, metaclass = ProtocolClass ):
215224

216225

217226
class ProtocolMutable(
218-
__.typx.Protocol, metaclass = ProtocolClass, instances_mutables = '*'
227+
__.typx.Protocol,
228+
metaclass = ProtocolClass,
229+
class_mutables = (
230+
'_abc_cache',
231+
'_abc_negative_cache',
232+
'_abc_negative_cache_version',
233+
'_abc_registry',
234+
),
235+
instances_mutables = '*',
219236
):
220237
''' Base protocol class with mutable instance attributes. '''
221238

@@ -226,7 +243,14 @@ class ProtocolMutable(
226243

227244

228245
class DataclassProtocol(
229-
__.typx.Protocol, metaclass = ProtocolDataclass,
246+
__.typx.Protocol,
247+
metaclass = ProtocolDataclass,
248+
class_mutables = (
249+
'_abc_cache',
250+
'_abc_negative_cache',
251+
'_abc_negative_cache_version',
252+
'_abc_registry',
253+
),
230254
):
231255
''' Standard base protocol dataclass. '''
232256

@@ -237,7 +261,14 @@ class DataclassProtocol(
237261

238262

239263
class DataclassProtocolMutable(
240-
__.typx.Protocol, metaclass = ProtocolDataclassMutable,
264+
__.typx.Protocol,
265+
metaclass = ProtocolDataclassMutable,
266+
class_mutables = (
267+
'_abc_cache',
268+
'_abc_negative_cache',
269+
'_abc_negative_cache_version',
270+
'_abc_registry',
271+
),
241272
):
242273
''' Base protocol dataclass with mutable instance attributes. '''
243274

0 commit comments

Comments
 (0)