Soy un programador de Argentina 🇦🇷🐍
wrrulos / easyjsonpy Goto Github PK
View Code? Open in Web Editor NEWPython library that allows you to easily load languages and settings into your project using JSON files
Python library that allows you to easily load languages and settings into your project using JSON files
Hello, I've found a small problem in the code. The affected methods are src.easyjsonpy.config_loader.ConfigLoader.get_config
and src.easyjsonpy.lang_loader.LangLoader.get_message
. The problem is in the combination of the lambda expression with the reduce
function. Imagine there is a dict like {'x': 1}
and a list (of keys) with length of 10,000,000 or more containing keys of which one or more do not exist in the dict or nested dicts (for example ['y', 'x', 'x', 'x', ... 'x']
). The reduce
function calls the lambda expression as many times as many keys are in the list. It looks like this:
def reduce(function, sequence, initial=_initial_missing):
it = iter(sequence)
if initial is _initial_missing:
try:
value = next(it)
except StopIteration:
raise TypeError(
"reduce() of empty iterable with no initial value") from None
else:
value = initial
for element in it:
value = function(value, element)
return value
Even if the very first lambda call returned None
, the function would still call the lambda expression 9,999,999 more times before the actual method get_config
or get_message
returns the final value (None
), because the isinstance
check in the lambda expression does not really stop the loop but only returns None
and reduce
function's loop just goes on (the isinstance
check would have to be placed in the reduce
function's loop). This is making the getting process take multiple seconds to finish with very long lists of keys (the more keys are in the list, the higher the time is), which is unnecessarily long and very inefficient for such a small dict. I know this only has a minimal impact as most likely no one will use such long lists of keys in practice, but I think this should be improved anyways.
Thanks!
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.