@@ -1080,7 +1080,7 @@ def __init__(
10801080 # Close and delete the temporary zipfile
10811081 try :
10821082 zipfileobj .close ()
1083- except : # pylint: disable=broad-exception-caught
1083+ except : # pylint: disable=bare-except
10841084 pass
10851085 # Try to load shapefile
10861086 if self .shp or self .dbf :
@@ -1230,7 +1230,7 @@ def __len__(self):
12301230 while pos < shpLength :
12311231 offsets .append (pos )
12321232 # Unpack the shape header only
1233- (recNum , recLength ) = unpack_2_int32_be (shp .read (8 ))
1233+ (__recNum , recLength ) = unpack_2_int32_be (shp .read (8 ))
12341234 # Jump to next shape position
12351235 pos += 8 + (2 * recLength )
12361236 shp .seek (pos )
@@ -1266,7 +1266,7 @@ def load(self, shapefile=None):
12661266 object. Normally this method would be called by the
12671267 constructor with the file name as an argument."""
12681268 if shapefile :
1269- (shapeName , ext ) = os .path .splitext (shapefile )
1269+ (shapeName , __ext ) = os .path .splitext (shapefile )
12701270 self .shapeName = shapeName
12711271 self .load_shp (shapeName )
12721272 self .load_shx (shapeName )
@@ -1386,6 +1386,8 @@ def __shpHeader(self):
13861386 raise ShapefileException (
13871387 "Shapefile Reader requires a shapefile or file-like object. (no shp file found"
13881388 )
1389+
1390+ # pylint: disable=attribute-defined-outside-init
13891391 shp = self .shp
13901392 # File length (16-bit word * 2 = bytes)
13911393 shp .seek (24 )
@@ -1406,14 +1408,17 @@ def __shpHeader(self):
14061408 else :
14071409 self .mbox .append (None )
14081410
1411+ # pylint: enable=attribute-defined-outside-init
1412+
14091413 def __shape (self , oid = None , bbox = None ):
14101414 """Returns the header info and geometry for a single shape."""
14111415
14121416 # pylint: disable=attribute-defined-outside-init
14131417 f = self .__getFileObj (self .shp )
14141418 record = Shape (oid = oid )
1415- nParts = nPoints = zmin = zmax = mmin = mmax = None
1416- (recNum , recLength ) = unpack (">2i" , f .read (8 ))
1419+ # Formerly we also set __zmin = __zmax = __mmin = __mmax = None
1420+ nParts = nPoints = None
1421+ (__recNum , recLength ) = unpack (">2i" , f .read (8 ))
14171422 # Determine the start of the next record
14181423 next_shape = f .tell () + (2 * recLength )
14191424 shapeType = unpack ("<i" , f .read (4 ))[0 ]
@@ -1448,12 +1453,12 @@ def __shape(self, oid=None, bbox=None):
14481453 record .points = list (zip (* (iter (flat ),) * 2 ))
14491454 # Read z extremes and values
14501455 if shapeType in (13 , 15 , 18 , 31 ):
1451- ( zmin , zmax ) = unpack ("<2d" , f .read (16 ))
1456+ __zmin , __zmax = unpack ("<2d" , f .read (16 ))
14521457 record .z = _Array ("d" , unpack (f"<{ nPoints } d" , f .read (nPoints * 8 )))
14531458 # Read m extremes and values
14541459 if shapeType in (13 , 15 , 18 , 23 , 25 , 28 , 31 ):
14551460 if next_shape - f .tell () >= 16 :
1456- ( mmin , mmax ) = unpack ("<2d" , f .read (16 ))
1461+ __mmin , __mmax = unpack ("<2d" , f .read (16 ))
14571462 # Measure values less than -10e38 are nodata values according to the spec
14581463 if next_shape - f .tell () >= nPoints * 8 :
14591464 record .m = []
@@ -1557,7 +1562,7 @@ def shape(self, i=0, bbox=None):
15571562 # Reached the requested index, exit loop with the offset value
15581563 break
15591564 # Unpack the shape header only
1560- (recNum , recLength ) = unpack_2_int32_be (shp .read (8 ))
1565+ (__recNum , recLength ) = unpack_2_int32_be (shp .read (8 ))
15611566 # Jump to next shape position
15621567 offset += 8 + (2 * recLength )
15631568 shp .seek (offset )
@@ -1625,6 +1630,8 @@ def iterShapes(self, bbox=None):
16251630
16261631 def __dbfHeader (self ):
16271632 """Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger"""
1633+
1634+ # pylint: disable=attribute-defined-outside-init
16281635 if not self .dbf :
16291636 raise ShapefileException (
16301637 "Shapefile Reader requires a shapefile or file-like object. (no dbf file found)"
@@ -1638,7 +1645,7 @@ def __dbfHeader(self):
16381645
16391646 # read fields
16401647 numFields = (self .__dbfHdrLength - 33 ) // 32
1641- for field in range (numFields ):
1648+ for __field in range (numFields ):
16421649 fieldDesc = list (unpack ("<11sc4xBB14x" , dbf .read (32 )))
16431650 name = 0
16441651 idx = 0
@@ -1667,10 +1674,12 @@ def __dbfHeader(self):
16671674 # by default, read all fields except the deletion flag, hence "[1:]"
16681675 # note: recLookup gives the index position of a field inside a _Record list
16691676 fieldnames = [f [0 ] for f in self .fields [1 :]]
1670- fieldTuples , recLookup , recStruct = self .__recordFields (fieldnames )
1677+ __fieldTuples , recLookup , recStruct = self .__recordFields (fieldnames )
16711678 self .__fullRecStruct = recStruct
16721679 self .__fullRecLookup = recLookup
16731680
1681+ # pylint: enable=attribute-defined-outside-init
1682+
16741683 def __recordFmt (self , fields = None ):
16751684 """Calculates the format and size of a .dbf record. Optional 'fields' arg
16761685 specifies which fieldnames to unpack and which to ignore. Note that this
@@ -1709,7 +1718,7 @@ def __recordFields(self, fields=None):
17091718 # first ignore repeated field names (order doesn't matter)
17101719 fields = list (set (fields ))
17111720 # get the struct
1712- fmt , fmtSize = self .__recordFmt (fields = fields )
1721+ fmt , __fmtSize = self .__recordFmt (fields = fields )
17131722 recStruct = Struct (fmt )
17141723 # make sure the given fieldnames exist
17151724 for name in fields :
@@ -1762,7 +1771,7 @@ def __record(
17621771
17631772 # parse each value
17641773 record = []
1765- for (name , typ , size , deci ), value in zip (fieldTuples , recordContents ):
1774+ for (__name , typ , __size , deci ), value in zip (fieldTuples , recordContents ):
17661775 if typ in ("N" , "F" ):
17671776 # numeric or float: number stored as a string, right justified, and padded with blanks to the width of the field.
17681777 value = value .split (b"\0 " )[0 ]
@@ -2980,7 +2989,7 @@ def _test(args: list[str] = sys.argv[1:], verbosity: bool = False) -> int:
29802989
29812990 if verbosity == 0 :
29822991 print (f"Running { len (tests .examples )} doctests..." )
2983- failure_count , test_count = runner .run (tests )
2992+ failure_count , __test_count = runner .run (tests )
29842993
29852994 # print results
29862995 if verbosity :
0 commit comments