Replies: 2 comments
-
P.S. Writing documentation (and PRs, docstrings, and discussions) arguably takes more work than writing code. Richard Dawkins describes writing as an evolutionary process, which is apt coming from him. I have found that remark helpful. I don't expect to create great writing in one go any more than I expect to write perfect code the first time! More importantly, it's fun to see writing take shape—to see evolution in action. I much prefer having too much writing to work with at first. I can then revise (evolve) what I have. But it's hard to revise writing that doesn't exist. |
Beta Was this translation helpful? Give feedback.
-
I don't remember why I said the deleted words, but they no longer apply. This discussion is a prelude to a PR that would simplify Rope's class structure. |
Beta Was this translation helpful? Give feedback.
-
This discussion is pre-writing for one section of the Theory of Operation. See #660.
Overview of the
Abstract
classesThere are three
Abstract
classes:AbstractClass
,AbstractFunction
, andAbstractModule
.Notation: Let
AbstractX
(or justAbstract
) denote one of these three classes.Rope's inference code contains many tests of the form
if isinstance(obj, AbstractX):
The primary purpose of the
Abstract
classes is to make these tests.In other words, the
Abstract
classes "mark" classes as the base of Rope's type hierarchy. See the next section.The
Abstract
classes do three things:Abstract
classes make a class a subclasses of thePyObject
class.PyObject
class.Abstract
classes help init thePyObject
class: TheAbstract
classes have ctors of the form:where
X
isModule
, orFunction
, butType
instead ofClass
. Why? Because in Python the type of a class (not an instance) istype
:prints
<class 'type'>
.The Data model chapter of the Python language manual provides a wealth of gory details, which happily we can mostly ignore.
The 9 subclasses of
AbstractX
Let
b
andpo
denote Rope'sbuiltins
andpyobjects
modules respectively.Rope's codebase defines 9 subclasses of the three
Abstract
classes:AbstractModule
:po._PyModule
andb.BuiltinModule
.AbstractClass
:po.PyClass
,b.BuiltinClass
,b.Generator
, andb.Iterator
.AbstractFunction
:po.PyFunction
,b.BuiltinFunction
, andb.Lambda
.Summary
Abstract
classes mark 9 other classes as the base of the Rope's type hierarchy.There are other ways of marking these classes, but exactly these 9 classes must be marked somehow.
Tests of the form
if isinstance(obj, AbstractX)
areTrue
if obj (aPyObject
) is a base of Rope's type hierarchy.Beta Was this translation helpful? Give feedback.
All reactions