mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-10-31 16:07:41 +03:00 
			
		
		
		
	Fix #1375 -- out-of-bounds on token.nbor()
This commit is contained in:
		
							parent
							
								
									a68d89a4f3
								
							
						
					
					
						commit
						b66b8f028b
					
				|  | @ -3,7 +3,7 @@ import pytest | |||
| from ...vocab import Vocab | ||||
| from ...tokens.doc import Doc | ||||
| 
 | ||||
| @pytest.mark.xfail | ||||
| 
 | ||||
| def test_issue1375(): | ||||
|     '''Test that token.nbor() raises IndexError for out-of-bounds access.''' | ||||
|     doc = Doc(Vocab(), words=['0', '1', '2']) | ||||
|  |  | |||
|  | @ -127,6 +127,9 @@ cdef class Token: | |||
|         i (int): The relative position of the token to get. Defaults to 1. | ||||
|         RETURNS (Token): The token at position `self.doc[self.i+i]`. | ||||
|         """ | ||||
|         if self.i+i < 0 or (self.i+i >= len(self.doc)): | ||||
|             msg = "Error accessing doc[%d].nbor(%d), for doc of length %d" | ||||
|             raise IndexError(msg % (self.i, i, len(self.doc))) | ||||
|         return self.doc[self.i+i] | ||||
| 
 | ||||
|     def similarity(self, other): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user