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

8 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-07 16:32 +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''' Standard annotations across Python versions. ''' 

22 

23# ruff: noqa: F401 

24# pylint: disable=unused-import 

25 

26 

27from types import ModuleType as Module 

28 

29from typing_extensions import ( 

30 Annotated as Annotation, 

31 Any, 

32 Callable, 

33 Collection, # TODO: Python 3.9: collections.abc.Collection 

34 Dict, # TODO: Python 3.9: dict 

35 Doc, 

36 Hashable, # TODO: Python 3.9: collections.abc.Hashable 

37 ItemsView, # TODO: Python 3.9: collections.abc.ItemsView 

38 Iterable, # TODO: Python 3.9: collections.abc.Iterable 

39 Iterator, # TODO: Python 3.9: collections.abc.Iterator 

40 KeysView, # TODO: Python 3.9: collections.abc.KeysView 

41 Mapping, # TODO: Python 3.9: collections.abc.Mapping 

42 MutableMapping, # TODO: Python 3.9: collections.abc.MutableMapping 

43 Never, 

44 Self, 

45 Tuple, # TODO: Python 3.9: collections.abc.Sequence 

46 Type, # TODO: Python 3.9: type 

47 TypeAlias, 

48 Union, # TODO: Python 3.10: bitwise-OR operator ('|') 

49 ValuesView, # TODO: Python 3.9: collections.abc.ValuesView 

50 cast, 

51) 

52 

53 

54# TODO? Python 3.10: Import 'NotImplementedType' from 'types'. 

55# Note: According to https://stackoverflow.com/a/75185542/14833542, 

56# Mypy implicitly considers 'NotImplemented' as a result of the dunder 

57# methods for comparison. 

58#ComparisonResult: TypeAlias = Union[ bool, NotImplementedType ] 

59ComparisonResult: TypeAlias = bool 

60 

61DictionaryNominativeArgument: TypeAlias = Annotation[ 

62 Any, 

63 Doc( 

64 'Zero or more keyword arguments from which to initialize ' 

65 'dictionary data.' ) 

66] 

67 

68# TODO: Support taking our dictionaries, themselves, as arguments. 

69# Supposed to work via structural typing, but must match protocol. 

70# https://github.com/python/mypy/issues/2922 

71# https://github.com/python/mypy/issues/2922#issuecomment-1186587232 

72# https://github.com/python/typing/discussions/1127#discussioncomment-2538837 

73# https://mypy.readthedocs.io/en/latest/protocols.html 

74DictionaryPositionalArgument: TypeAlias = Annotation[ 

75 Union[ Mapping[ Hashable, Any ], Iterable[ Tuple[ Hashable, Any] ] ], 

76 Doc( 

77 'Zero or more iterables from which to initialize dictionary data. ' 

78 'Each iterable must be dictionary or sequence of key-value pairs. ' 

79 'Duplicate keys will result in an error.' ) 

80] 

81 

82DictionaryProducer: TypeAlias = Annotation[ 

83 Callable[ [ ], Any ], 

84 Doc( 'Callable which produces values for absent dictionary entries.' ) 

85] 

86 

87ModuleReclassifier: TypeAlias = Callable[ [ Mapping[ str, Any ] ], None ] 

88 

89 

90__all__ = ( )