Coverage for sources/accretive/namespaces.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-06 17:17 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

4#============================================================================# 

5# # 

6# Licensed under the Apache License, Version 2.0 (the "License"); # 

7# you may not use this file except in compliance with the License. # 

8# You may obtain a copy of the License at # 

9# # 

10# http://www.apache.org/licenses/LICENSE-2.0 # 

11# # 

12# Unless required by applicable law or agreed to in writing, software # 

13# distributed under the License is distributed on an "AS IS" BASIS, # 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

15# See the License for the specific language governing permissions and # 

16# limitations under the License. # 

17# # 

18#============================================================================# 

19 

20 

21''' Accretive namespaces. ''' 

22 

23 

24from . import __ 

25from . import _annotations as _a 

26from . import objects as _objects 

27 

28 

29class Namespace( _objects.Object ): # pylint: disable=eq-without-hash 

30 ''' Accretive namespaces. ''' 

31 

32 def __init__( 

33 self, 

34 *iterables: _a.DictionaryPositionalArgument, 

35 **attributes: _a.DictionaryNominativeArgument 

36 ) -> None: 

37 super( ).__init__( ) 

38 super( ).__getattribute__( '__dict__' ).update( 

39 *iterables, **attributes ) 

40 

41 def __repr__( self ) -> str: 

42 attributes = ', '.join( tuple( 

43 f"{key} = {value!r}" for key, value 

44 in super( ).__getattribute__( '__dict__' ).items( ) ) ) 

45 fqname = __.discover_fqname( self ) 

46 if not attributes: return f"{fqname}( )" 

47 return f"{fqname}( {attributes} )" 

48 

49 def __eq__( self, other: _a.Any ) -> _a.ComparisonResult: 

50 mydict = super( ).__getattribute__( '__dict__' ) 

51 if isinstance( other, ( Namespace, __.SimpleNamespace ) ): 

52 return mydict == other.__dict__ # type: ignore[no-any-return] 

53 return NotImplemented 

54 

55 def __ne__( self, other: _a.Any ) -> _a.ComparisonResult: 

56 mydict = super( ).__getattribute__( '__dict__' ) 

57 if isinstance( other, ( Namespace, __.SimpleNamespace ) ): 

58 return mydict != other.__dict__ # type: ignore[no-any-return] 

59 return NotImplemented 

60 

61Namespace.__doc__ = __.generate_docstring( 

62 Namespace, 'description of namespace', 'instance attributes accretion' ) 

63 

64 

65__all__ = __.discover_public_attributes( globals( ) )