comparison configmix/yaml.py @ 207:b3b5ed34d180

Handle most flake8 errors and warnings. NOTE: E265 "block comment should start with '# ' ist not yet handled. We would need to adjust our Python style.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 05 May 2019 18:29:47 +0200
parents e2e8d21b4122
children bbe8513ea649
comparison
equal deleted inserted replaced
206:5064e3a2e54a 207:b3b5ed34d180
59 59
60 def construct_mapping(self, node, deep=False): 60 def construct_mapping(self, node, deep=False):
61 if isinstance(node, yaml.MappingNode): 61 if isinstance(node, yaml.MappingNode):
62 self.flatten_mapping(node) 62 self.flatten_mapping(node)
63 else: 63 else:
64 raise yaml.constructor.ConstructorError(None, None, 64 raise yaml.constructor.ConstructorError(
65 None,
66 None,
65 'expected a mapping node, but found %s' % node.id, 67 'expected a mapping node, but found %s' % node.id,
66 node.start_mark) 68 node.start_mark)
67 69
68 mapping = OrderedDict() 70 mapping = OrderedDict()
69 for key_node, value_node in node.value: 71 for key_node, value_node in node.value:
71 try: 73 try:
72 hash(key) 74 hash(key)
73 except TypeError as err: 75 except TypeError as err:
74 raise yaml.constructor.ConstructorError( 76 raise yaml.constructor.ConstructorError(
75 'while constructing a mapping', node.start_mark, 77 'while constructing a mapping', node.start_mark,
76 'found unacceptable key (%s)' % err, key_node.start_mark) 78 'found unacceptable key (%s)' % (err,
79 key_node.start_mark)
80 )
77 value = self.construct_object(value_node, deep=deep) 81 value = self.construct_object(value_node, deep=deep)
78 mapping[key] = value 82 mapping[key] = value
79 return mapping 83 return mapping
80 84
81 85
121 125
122 def construct_mapping(self, node, deep=False): 126 def construct_mapping(self, node, deep=False):
123 if isinstance(node, yaml.MappingNode): 127 if isinstance(node, yaml.MappingNode):
124 self.flatten_mapping(node) 128 self.flatten_mapping(node)
125 else: 129 else:
126 raise yaml.constructor.ConstructorError(None, None, 130 raise yaml.constructor.ConstructorError(
131 None,
132 None,
127 'expected a mapping node, but found %s' % node.id, 133 'expected a mapping node, but found %s' % node.id,
128 node.start_mark) 134 node.start_mark)
129 135
130 mapping = OrderedDict() 136 mapping = OrderedDict()
131 for key_node, value_node in node.value: 137 for key_node, value_node in node.value:
133 try: 139 try:
134 hash(key) 140 hash(key)
135 except TypeError as err: 141 except TypeError as err:
136 raise yaml.constructor.ConstructorError( 142 raise yaml.constructor.ConstructorError(
137 'while constructing a mapping', node.start_mark, 143 'while constructing a mapping', node.start_mark,
138 'found unacceptable key (%s)' % err, key_node.start_mark) 144 'found unacceptable key (%s)' % (err,
145 key_node.start_mark)
146 )
139 value = self.construct_object(value_node, deep=deep) 147 value = self.construct_object(value_node, deep=deep)
140 mapping[key] = value 148 mapping[key] = value
141 return mapping 149 return mapping
142 150
143 151