Modify

Ticket #110 (new enhancement)

Opened 5 years ago

remove unused "if" statements

Reported by: py4fun@… Owned by: xi
Priority: low Component: pyyaml
Severity: minor Keywords:
Cc:

Description

Remove "if" statements which are always evaluated to the same result from resolver, scanner and serializer

Index: lib/yaml/resolver.py
===================================================================
--- lib/yaml/resolver.py	(revision 307)
+++ lib/yaml/resolver.py	(working copy)
@@ -158,7 +158,7 @@
             return self.DEFAULT_SCALAR_TAG
         elif kind is SequenceNode:
             return self.DEFAULT_SEQUENCE_TAG
-        elif kind is MappingNode:
+        else:
             return self.DEFAULT_MAPPING_TAG
 
 class Resolver(BaseResolver):
Index: lib/yaml/scanner.py
===================================================================
--- lib/yaml/scanner.py	(revision 307)
+++ lib/yaml/scanner.py	(working copy)
@@ -126,13 +126,10 @@
         # Return the next token, but do not delete if from the queue.
         while self.need_more_tokens():
             self.fetch_more_tokens()
-        if self.tokens:
-            return self.tokens[0]
+        return self.tokens[0]
 
     def get_token(self):
         # Return the next token.
-        while self.need_more_tokens():
-            self.fetch_more_tokens()
         if self.tokens:
             self.tokens_taken += 1
             return self.tokens.pop(0)
Index: lib/yaml/serializer.py
===================================================================
--- lib/yaml/serializer.py	(revision 307)
+++ lib/yaml/serializer.py	(working copy)
@@ -98,7 +98,7 @@
                     self.serialize_node(item, node, index)
                     index += 1
                 self.emit(SequenceEndEvent())
-            elif isinstance(node, MappingNode):
+            else: # MappingNode
                 implicit = (node.tag
                             == self.resolve(MappingNode, node.value, True))
                 self.emit(MappingStartEvent(alias, node.tag, implicit,

Attachments

less-if.patch Download (1.7 KB) - added by py4fun@… 5 years ago.

Change History

Changed 5 years ago by py4fun@…

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.