280 field = getattr(node, name, None) |
280 field = getattr(node, name, None) |
281 if isinstance(field, ast.AST): |
281 if isinstance(field, ast.AST): |
282 yield field |
282 yield field |
283 elif isinstance(field, list): |
283 elif isinstance(field, list): |
284 for item in field: |
284 for item in field: |
285 yield item |
285 if isinstance(item, ast.AST): |
|
286 yield item |
286 |
287 |
287 |
288 |
288 def convert_to_value(item): |
289 def convert_to_value(item): |
289 if isinstance(item, ast.Str): |
290 if isinstance(item, ast.Str): |
290 return item.s |
291 return item.s |
696 # Returns node.id, or node.name, or None |
697 # Returns node.id, or node.name, or None |
697 if hasattr(node, 'id'): # One of the many nodes with an id |
698 if hasattr(node, 'id'): # One of the many nodes with an id |
698 return node.id |
699 return node.id |
699 if hasattr(node, 'name'): # an ExceptHandler node |
700 if hasattr(node, 'name'): # an ExceptHandler node |
700 return node.name |
701 return node.name |
|
702 if hasattr(node, 'rest'): # a MatchMapping node |
|
703 return node.rest |
701 |
704 |
702 |
705 |
703 TYPING_MODULES = frozenset(('typing', 'typing_extensions')) |
706 TYPING_MODULES = frozenset(('typing', 'typing_extensions')) |
704 |
707 |
705 |
708 |
722 is_name_match_fn(scope[name].real_name) |
725 is_name_match_fn(scope[name].real_name) |
723 ) |
726 ) |
724 |
727 |
725 return False |
728 return False |
726 |
729 |
|
730 def _module_scope_is_typing(name): |
|
731 for scope in reversed(scope_stack): |
|
732 if name in scope: |
|
733 return ( |
|
734 isinstance(scope[name], Importation) and |
|
735 scope[name].fullName in TYPING_MODULES |
|
736 ) |
|
737 |
|
738 return False |
|
739 |
727 return ( |
740 return ( |
728 ( |
741 ( |
729 isinstance(node, ast.Name) and |
742 isinstance(node, ast.Name) and |
730 _bare_name_is_attr(node.id) |
743 _bare_name_is_attr(node.id) |
731 ) or ( |
744 ) or ( |
732 isinstance(node, ast.Attribute) and |
745 isinstance(node, ast.Attribute) and |
733 isinstance(node.value, ast.Name) and |
746 isinstance(node.value, ast.Name) and |
734 node.value.id in TYPING_MODULES and |
747 _module_scope_is_typing(node.value.id) and |
735 is_name_match_fn(node.attr) |
748 is_name_match_fn(node.attr) |
736 ) |
749 ) |
737 ) |
750 ) |
738 |
751 |
739 |
752 |
1398 if node is None: |
1410 if node is None: |
1399 return |
1411 return |
1400 if self.offset and getattr(node, 'lineno', None) is not None: |
1412 if self.offset and getattr(node, 'lineno', None) is not None: |
1401 node.lineno += self.offset[0] |
1413 node.lineno += self.offset[0] |
1402 node.col_offset += self.offset[1] |
1414 node.col_offset += self.offset[1] |
1403 if self.traceTree: |
|
1404 print(' ' * self.nodeDepth + node.__class__.__name__) |
|
1405 if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or |
1415 if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or |
1406 self.isDocstring(node)): |
1416 self.isDocstring(node)): |
1407 self.futuresAllowed = False |
1417 self.futuresAllowed = False |
1408 self.nodeDepth += 1 |
1418 self.nodeDepth += 1 |
1409 node._pyflakes_depth = self.nodeDepth |
1419 node._pyflakes_depth = self.nodeDepth |
2388 ): |
2396 ): |
2389 self.report(messages.IsLiteral, node) |
2397 self.report(messages.IsLiteral, node) |
2390 left = right |
2398 left = right |
2391 |
2399 |
2392 self.handleChildren(node) |
2400 self.handleChildren(node) |
|
2401 |
|
2402 MATCH = MATCH_CASE = MATCHCLASS = MATCHOR = MATCHSEQUENCE = handleChildren |
|
2403 MATCHSINGLETON = MATCHVALUE = handleChildren |
|
2404 |
|
2405 def _match_target(self, node): |
|
2406 self.handleNodeStore(node) |
|
2407 self.handleChildren(node) |
|
2408 |
|
2409 MATCHAS = MATCHMAPPING = MATCHSTAR = _match_target |