stestagg / fin Goto Github PK
View Code? Open in Web Editor NEWpython utility library
python utility library
When fin.cache.method is used on a classmethod, the cached values are shared between all subclasses in a non-stable fashion. For example:
class A(object):
BAR = 1
@classmethod
@fin.cache.method
def foo(cls):
return cls.BAR
class B(A):
BAR = 2
If the following code is then run:
print A.foo()
print B.foo()
then the output is:
1
1
If, however, this is run instead:
print B.foo()
print A.foo()
then the output is:
2
1
This is due to the naive way fin.cache stores cached values in the dict of the class. It will only create a new cache dictionary on the object if an existing one isn't found, this breaks even more thoroughly when classmethod caches and instance caches are mixed.
The obvious way around this is to interact with the dict attribute directly, unfortunately class objects use a 'dictproxy' object for their dict attribute, which doesn't allow item assignment directly, preventing such simple manipulation.
The approach that should work would be to /test/ for attribute presence by using "in" on the dict directly:
CACHE_KEY in obj.__dict__
rather than:
hasattr(obj, CACHE_KEY)
And then to use setattr() to write the new cache if this test fails.
Does this have a use?
It is honestly just a single class, called Exception, which inherits Pythons Exception, and then does absolutely nothing.
This looks like a big waste of time and just obfuscates what it actually is when you could just use Python's standard Exception class.
Sorry if this isn't welcome! I just came to take a look from mu as I was interested in what fin is. Found the exception module quite curious.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.