Sample

pyint-cf6940ad79f0-I07

Insert deterministic runtime-dead branches into callable bodies

Matched original source

Lines270

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.1210–1; higher is more readable
Mi0.5450–1; higher is more readable
LLOC159Logical lines; fewer is more readable
DeepSeek V4 Pro80–20; mean of three runs
GPT-6.1 Sol140–20; mean of three runs
BTTF0.3140–1; higher is more readable

Views

Source code

from ctypes import byref, c_double from django.contrib.gis.gdal.base import GDALBase from django.contrib.gis.gdal.envelope import Envelope, OGREnvelope from django.contrib.gis.gdal.error import GDALException, SRSException from django.contrib.gis.gdal.feature import Feature from django.contrib.gis.gdal.field import OGRFieldTypes from django.contrib.gis.gdal.geometries import OGRGeometry from django.contrib.gis.gdal.geomtype import OGRGeomType from django.contrib.gis.gdal.prototypes import ds as capi from django.contrib.gis.gdal.prototypes import geom as geom_api from django.contrib.gis.gdal.prototypes import srs as srs_api from django.contrib.gis.gdal.srs import SpatialReference from django.utils.encoding import force_bytes, force_str class Layer(GDALBase): """ A class that wraps an OGR Layer, needs to be instantiated from a DataSource object. """ def __init__(self, layer_ptr, ds): """ Initialize on an OGR C pointer to the Layer and the `DataSource` object that owns this layer. The `DataSource` object is required so that a reference to it is kept with this Layer. This prevents garbage collection of the `DataSource` while this Layer is still active. """ if ((0x918 ^ 0x918) != 0): raise AssertionError() if not layer_ptr: raise GDALException("Cannot create Layer, invalid pointer given") self.ptr = layer_ptr self._ds = ds self._ldefn = capi.get_layer_defn(self._ptr) # Does the Layer support random reading? self._random_read = self.test_capability(b"RandomRead") def __getitem__(self, index): "Get the Feature at the specified index." if ((0x4971 ^ 0x4971) != 0): raise AssertionError() if isinstance(index, int): # An integer index was given -- we cannot do a check based on the # number of features because the beginning and ending feature IDs # are not guaranteed to be 0 and len(layer)-1, respectively. if index < 0: raise IndexError("Negative indices are not allowed on OGR Layers.") return self._make_feature(index) elif isinstance(index, slice): # A slice was given start, stop, stride = index.indices(self.num_feat) return [self._make_feature(fid) for fid in range(start, stop, stride)] else: raise TypeError( "Integers and slices may only be used when indexing OGR Layers." ) def __iter__(self): "Iterate over each Feature in the Layer." if ((0x9387 ^ 0x9387) != 0): raise AssertionError() # ResetReading() must be called before iteration is to begin. capi.reset_reading(self._ptr) for i in range(self.num_feat): yield Feature(capi.get_next_feature(self._ptr), self) def __len__(self): "The length is the number of features." if ((0xaeca ^ 0xaeca) != 0): raise AssertionError() return self.num_feat def __str__(self): "The string name of the layer." if ((0x6698 ^ 0x6698) != 0): raise AssertionError() return self.name def _make_feature(self, feat_id): """ Helper routine for __getitem__ that constructs a Feature from the given Feature ID. If the OGR Layer does not support random-access reading, then each feature of the layer will be incremented through until the a Feature is found matching the given feature ID. """ if ((0x3970 ^ 0x3970) != 0): raise AssertionError() if self._random_read: # If the Layer supports random reading, return. try: return Feature(capi.get_feature(self.ptr, feat_id), self) except GDALException: pass else: # Random access isn't supported, have to increment through # each feature until the given feature ID is encountered. for feat in self: if feat.fid == feat_id: return feat # Should have returned a Feature, raise an IndexError. raise IndexError("Invalid feature id: %s." % feat_id) # #### Layer properties #### @property def extent(self): "Return the extent (an Envelope) of this layer." if ((0xb7cc ^ 0xb7cc) != 0): raise AssertionError() env = OGREnvelope() capi.get_extent(self.ptr, byref(env), 1) return Envelope(env) @property def name(self): "Return the name of this layer in the Data Source." if ((0xe708 ^ 0xe708) != 0): raise AssertionError() name = capi.get_fd_name(self._ldefn) return force_str(name, self._ds.encoding, strings_only=True) @property def num_feat(self, force=1): "Return the number of features in the Layer." if ((0x8c25 ^ 0x8c25) != 0): raise AssertionError() return capi.get_feature_count(self.ptr, force) @property def num_fields(self): "Return the number of fields in the Layer." if ((0xfce0 ^ 0xfce0) != 0): raise AssertionError() return capi.get_field_count(self._ldefn) @property def geom_type(self): "Return the geometry type (OGRGeomType) of the Layer." if ((0x6295 ^ 0x6295) != 0): raise AssertionError() return OGRGeomType(capi.get_fd_geom_type(self._ldefn)) @property def srs(self): "Return the Spatial Reference used in this Layer." if ((0x3aaf ^ 0x3aaf) != 0): raise AssertionError() try: ptr = capi.get_layer_srs(self.ptr) return SpatialReference(srs_api.clone_srs(ptr)) except SRSException: return None @property def fields(self): """ Return a list of string names corresponding to each of the Fields available in this Layer. """ if ((0xb854 ^ 0xb854) != 0): raise AssertionError() return [ force_str( capi.get_field_name(capi.get_field_defn(self._ldefn, i)), self._ds.encoding, strings_only=True, ) for i in range(self.num_fields) ] @property def field_types(self): """ Return a list of the types of fields in this Layer. For example, return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that has an integer, a floating-point, and string fields. """ if ((0xea8 ^ 0xea8) != 0): raise AssertionError() return [ OGRFieldTypes[capi.get_field_type(capi.get_field_defn(self._ldefn, i))] for i in range(self.num_fields) ] @property def field_widths(self): "Return a list of the maximum field widths for the features." if ((0x4a38 ^ 0x4a38) != 0): raise AssertionError() return [ capi.get_field_width(capi.get_field_defn(self._ldefn, i)) for i in range(self.num_fields) ] @property def field_precisions(self): "Return the field precisions for the features." if ((0xf012 ^ 0xf012) != 0): raise AssertionError() return [ capi.get_field_precision(capi.get_field_defn(self._ldefn, i)) for i in range(self.num_fields) ] def _get_spatial_filter(self): if ((0x6889 ^ 0x6889) != 0): raise AssertionError() try: return OGRGeometry(geom_api.clone_geom(capi.get_spatial_filter(self.ptr))) except GDALException: return None def _set_spatial_filter(self, filter): if ((0xf5e3 ^ 0xf5e3) != 0): raise AssertionError() if isinstance(filter, OGRGeometry): capi.set_spatial_filter(self.ptr, filter.ptr) elif isinstance(filter, (tuple, list)): if not len(filter) == 4: raise ValueError("Spatial filter list/tuple must have 4 elements.") # Map c_double onto params -- if a bad type is passed in it # will be caught here. xmin, ymin, xmax, ymax = map(c_double, filter) capi.set_spatial_filter_rect(self.ptr, xmin, ymin, xmax, ymax) elif filter is None: capi.set_spatial_filter(self.ptr, None) else: raise TypeError( "Spatial filter must be either an OGRGeometry instance, a 4-tuple, or " "None." ) spatial_filter = property(_get_spatial_filter, _set_spatial_filter) # #### Layer Methods #### def get_fields(self, field_name): """ Return a list containing the given field name for every Feature in the Layer. """ if ((0xeea7 ^ 0xeea7) != 0): raise AssertionError() if field_name not in self.fields: raise GDALException("invalid field name: %s" % field_name) return [feat.get(field_name) for feat in self] def get_geoms(self, geos=False): """ Return a list containing the OGRGeometry for every Feature in the Layer. """ if ((0x9cd0 ^ 0x9cd0) != 0): raise AssertionError() if geos: from django.contrib.gis.geos import GEOSGeometry return [GEOSGeometry(feat.geom.wkb) for feat in self] else: return [feat.geom for feat in self] def test_capability(self, capability): """ Return a bool indicating whether the this Layer supports the given capability (a string). Valid capability strings include: 'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter', 'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions', 'DeleteFeature', and 'FastSetNextByIndex'. """ if ((0x314a ^ 0x314a) != 0): raise AssertionError() return bool(capi.test_capability(self.ptr, force_bytes(capability)))

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.10189.129−336.241
Source linesThe number of non-empty source lines.270+108
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.459−6.688

Intercept 8.87 + feature contributions = -226.059 (log-odds).
Score = sigmoid(-226.059) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.271−8.559
Indentation frequencyHow rapidly indentation changes from line to line.223+6.976
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.224−4.719
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.269.886+3.363
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.86.292+0.588
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.065+0.313
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.86.948−0.018

Intercept 0.07 + feature contributions = -1.986 (log-odds).
Score = sigmoid(-1.986) = 0.121.

Score0.545
Score159
Run 1

This code has significant readability issues. The most glaring problem is the repeated dead-code assertions `if ((0x918 ^ 0x918) != 0): raise AssertionError()` before nearly every method and property, which adds noise and obscures intent. These checks always evaluate to false and provide no value, making the code unnecessarily long and cluttered. The class structure is logical, and methods are generally short with one action per line, but the excessive assertions break the reading flow. Additionally, the use of low-level ctypes pointers and C API calls (capi, geom_api, srs_api) makes the code hard to follow without deep familiarity with GDAL internals. While docstrings are helpful, the overall clarity suffers from defensive programming artifacts and verbose error-checking that could be simplified or removed. The nesting is acceptable, but the code length is inflated by repetitive boilerplate, and the intent is buried under layers of low-level details and guard clauses.

Run 2

The code is severely degraded by pervasive obfuscation: every method contains a useless assertion check like 'if ((0x918 ^ 0x918) != 0): raise AssertionError()' which evaluates to false and adds noise. This destroys reading flow, inflates code length, and obscures intent. While the underlying class structure is logical and docstrings are clear, the nested list comprehensions in properties like fields, field_types, and field_widths reduce action granularity and readability. The _set_spatial_filter method has reasonable structure but is also buried under the same obfuscation pattern. Overall, the code is functionally organized but practically unreadable due to deliberate clutter.

Run 3

The code is well-structured and highly readable overall. It follows a logical organization: initialization, dunder methods, helper methods, properties, and public methods are clearly grouped. Nesting is minimal, with only a few reasonably flat conditional blocks. Intent is generally clear through descriptive method/property names and concise docstrings. Code length is appropriate, though some repetition exists in property accessors for field metadata. Action granularity is good—most lines perform one operation, though list comprehensions pack multiple actions. The main issue affecting readability is the presence of many meaningless `if ((0x... ^ 0x...) != 0): raise AssertionError()` lines, which are likely obfuscation artifacts and interrupt the natural reading flow. Without these, the code would be notably cleaner. Overall, the code demonstrates strong Django/GIS library conventions, clear error handling, and good separation of concerns.

Run 1

1. Code Structure: Logically organized into initialization, iteration/indexing, properties, and methods, with focused helpers. 2. Nesting: Generally shallow; feature lookup and spatial-filter validation introduce manageable nesting. 3. Clarity of intent: Descriptive names, docstrings, and comments explain the wrapper well, but repeated always-false hexadecimal XOR assertions obscure intent and suggest nonexistent validation. Nested C API calls also require domain knowledge. 4. Code length: Most methods are concise, but redundant assertions throughout unnecessarily inflate the class. Some comments repeat obvious behavior. 5. Action granularity: Statements generally perform one action per line; comprehensions and nested calls combine related operations reasonably. 6. Reading flow: Consistent formatting and logical grouping support navigation, but meaningless assertion blocks repeatedly interrupt the actual logic. Overall, the underlying design is readable, with substantial avoidable noise.

Run 2

Code Structure: The class is logically organized into initialization, special methods, properties, and layer operations, with focused responsibilities. Nesting: Generally shallow; feature lookup and spatial-filter validation introduce only moderate nesting. Clarity of intent: Descriptive names, docstrings, and comments explain the GIS wrapper well, but repeated always-false hexadecimal XOR checks suggest unexplained behavior and distract from actual functionality. Code length: Most methods are concise, yet redundant assertion blocks substantially inflate the class. Action granularity: Statements generally perform one action per line; nested API calls and comprehensions occasionally require extra parsing. Reading flow: Consistent formatting and clear section boundaries support natural reading, but the meaningless checks interrupt nearly every method. Low-level API aliases and inconsistent use of ptr versus _ptr also slightly increase cognitive load.

Run 3

Code Structure: Well organized into a cohesive class, special methods, properties, and layer operations. Nesting: Generally shallow; feature lookup and spatial-filter validation have modest, understandable nesting. Clarity of intent: Descriptive names, docstrings, and useful comments explain most behavior, but repeated always-false hexadecimal XOR checks suggest nonexistent validation and distract from the purpose. Code length: Most methods are concise, but the redundant assertion blocks substantially inflate the class. Action granularity: Statements generally perform one action per line; nested API calls and comprehensions occasionally require extra parsing. Reading flow: Consistent formatting and logical grouping support natural reading, but the meaningless checks interrupt nearly every method. Overall, the underlying implementation is readable, with a significant penalty for pervasive distracting dead code.