Comments (2)
I like the comment from @PatrickHugh:
Instead of manipulating
__subclasses__
, I would recommend keeping your own list instead, possible through the__init_subclass__
hook
class Coin:
subcoins = []
def __init_subclass__(cls):
Coin.subcoins.append(cls)
@classmethod
def remove_subcoin(cls, coin):
Coin.subcoins.remove(cls)
Then instead of Coin.__subclasses__()
, use Coin.subcoins
.
from coinhandler.
Coin
already has a method for getting sub coins, added in 8b7aa0e: Coin.sub_coins()
.
Might be best to mark the list tracking the coins private.
__init_subclass__
should also ensure the coin isn't already in _subcoins
. So maybe this should be a set?
class Coin:
_subcoins = set()
def __init_subclass__(cls):
Coin._subcoins.add(cls)
@classmethod
def remove_subcoin(cls, coin):
Coin._subcoins.remove(cls)
from coinhandler.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coinhandler.