DEV Community

Discussion on: Recursive imports is the Achilles' heel of Python

Collapse
 
unfamiliarplace profile image
Luke Sawczak • Edited

...And God help you if the classes actually need each other. For example, suppose I'm modelling the grammar of a language that has recursive operations, e.g.

X -> (X + X)
X -> (X + Y)
X -> (Y + X)
Y -> (X + X)
Y -> (X + Z)
...etc.

If I define X and Y as distinct classes in separate files, then X will need to reference Y and Y will need to reference X. I can't think of a non-hacky way to do this.