Sample

pyint-cf52dd5e3ab4-I01

Remove comments and docstrings

Matched original source

Lines196

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.0940–1; higher is more readable
Mi0.3280–1; higher is more readable
LLOC97Logical lines; fewer is more readable
DeepSeek V4 Pro15.670–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.2980–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): def __init__(self, layer_ptr, ds): 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) self._random_read = self.test_capability(b"RandomRead") def __getitem__(self, index): if isinstance(index, int): if index < 0: raise IndexError("Negative indices are not allowed on OGR Layers.") return self._make_feature(index) elif isinstance(index, slice): 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): capi.reset_reading(self._ptr) for i in range(self.num_feat): yield Feature(capi.get_next_feature(self._ptr), self) def __len__(self): return self.num_feat def __str__(self): return self.name def _make_feature(self, feat_id): if self._random_read: try: return Feature(capi.get_feature(self.ptr, feat_id), self) except GDALException: pass else: for feat in self: if feat.fid == feat_id: return feat raise IndexError("Invalid feature id: %s." % feat_id) @property def extent(self): env = OGREnvelope() capi.get_extent(self.ptr, byref(env), 1) return Envelope(env) @property def name(self): 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 capi.get_feature_count(self.ptr, force) @property def num_fields(self): return capi.get_field_count(self._ldefn) @property def geom_type(self): return OGRGeomType(capi.get_fd_geom_type(self._ldefn)) @property def srs(self): try: ptr = capi.get_layer_srs(self.ptr) return SpatialReference(srs_api.clone_srs(ptr)) except SRSException: return None @property def fields(self): 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 [ 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 [ capi.get_field_width(capi.get_field_defn(self._ldefn, i)) for i in range(self.num_fields) ] @property def field_precisions(self): return [ capi.get_field_precision(capi.get_field_defn(self._ldefn, i)) for i in range(self.num_fields) ] def _get_spatial_filter(self): try: return OGRGeometry(geom_api.clone_geom(capi.get_spatial_filter(self.ptr))) except GDALException: return None def _set_spatial_filter(self, filter): 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.") 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) def get_fields(self, field_name): 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): 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 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.7270.56−239.928
Source linesThe number of non-empty source lines.196+78.4
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.249−6.374

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

Feature contributions

FeatureValueContribution
(log-odds)
Indentation frequencyHow rapidly indentation changes from line to line.195+6.008
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.197−5.939
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.195−4.054
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.195.909+2.329
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.0−0.804
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.082+0.148
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.985−0.019

Intercept 0.07 + feature contributions = -2.262 (log-odds).
Score = sigmoid(-2.262) = 0.094.

Score0.328
Score97
Run 1

The code is well-structured with a clear class definition, organized imports, and logical method grouping. Properties are concise and follow a consistent pattern. Nesting is generally minimal—only slices, filters, and random read fallbacks create moderate depth but remain manageable. Intent is explicit through descriptive method names, docstrings (albeit empty in places), and clean separation of concerns. Action granularity is strong: list comprehensions for field metadata, dedicated helper methods like _make_feature, and one main operation per line in most cases. Reading flow is natural—properties are grouped, methods are short, and error handling is localized. Minor deductions stem from inconsistent docstring completeness, some dense list comprehensions in fields/field_types, and slightly verbose repetitive patterns in field_widths/precisions. The spatial_filter setter has a few branches but remains readable. Overall, the code clearly expresses its purpose with structured, maintainable logic.

Run 2

The code is moderately readable, with clear class and method structure. Each method is short and focused on a single responsibility, and property names are descriptive. However, there are some areas that reduce clarity: several methods rely on low-level ctypes/capi calls with minimal abstraction, making intent less obvious. The __getitem__ method has an unusual triple-commented empty block, and _make_feature contains an implicit fallback loop with a swallowed exception, which could confuse readers. The list comprehensions in fields, field_types, etc., are compact but obscure the underlying operations. Overall, the code is organized and reasonably concise, but heavy reliance on opaque external calls and some non-obvious control flow keeps it from being highly readable.

Run 3

The code is generally well-structured and readable. It uses clear class organization with logical property definitions and method grouping. Nesting is minimal, with only small conditional blocks in indexing and spatial filter methods. Intent is mostly clear through descriptive method and property names like 'num_feat', 'geom_type', and 'test_capability'. Code length is appropriate for a GDAL wrapper, though some list comprehensions in field properties are slightly dense. Action granularity is good - most lines perform one operation, though the spatial filter tuple handling could be split further. Reading flow is natural, with properties grouped logically and docstrings explaining non-obvious sections. The main readability improvement would be consistent docstring content (some are empty) and slightly better error message context. The nested conditions in __getitem__ and _make_feature are acceptable but could be flattened with early returns.

Run 1

Code Structure: A cohesive Layer class separates feature access, metadata properties, spatial filtering, and utility methods logically. Nesting: Mostly shallow, with modest branching in indexing, feature lookup, and filter validation. Clarity of intent: Descriptive method names and explicit exceptions communicate purpose, but absent docstrings, abbreviated pointer/API names, and unexplained exception handling obscure some GDAL-specific behavior. Code length: Methods are concise, although repetitive metadata accessors and excessive blank lines inflate the presentation. Action granularity: Most statements perform one action; nested API calls and comprehensions occasionally combine several operations. Reading flow: Initialization followed by protocol methods, properties, and helpers is natural, but whitespace clutter and inconsistent use of ptr versus _ptr slightly disrupt readability.

Run 2

Code Structure: The class is logically organized into initialization, collection behavior, metadata properties, filtering, and utility methods. Nesting: Most methods are flat, with only modest nesting in feature lookup and filter validation. Clarity of intent: Descriptive method names and explicit error messages communicate purpose, but missing docstrings, abbreviated internal names, and low-level GDAL calls leave pointer ownership and lookup behavior unclear. Code length: Methods are concise, although excessive blank lines and repeated field-definition expressions add clutter. Action granularity: Statements generally perform one action per line; nested API calls and comprehensions occasionally combine several operations. Reading flow: The ordering is natural and consistent, but irregular whitespace, mixed use of ptr and _ptr, and silently caught exceptions interrupt comprehension.

Run 3

Code Structure: The class is logically organized into initialization, collection behavior, metadata properties, filtering, and utility methods. Nesting: Most methods are flat; indexing, feature retrieval, and filter validation have manageable nesting. Clarity of intent: Descriptive method names and explicit exceptions communicate purpose, but missing documentation, abbreviated native API names, and silent exception handling obscure some details. Code length: Methods are concise, although excessive blank lines and repeated field-definition lookups add visual bulk. Action granularity: Statements generally perform one action per line; nested API calls and comprehensions occasionally combine several operations. Reading flow: Consistent formatting and predictable method boundaries support natural reading, but whitespace clutter and inconsistent use of self.ptr versus self._ptr introduce minor distractions.