-
Notifications
You must be signed in to change notification settings - Fork 11
Implementation of str.upper and cleaning code #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ | |
|
|
||
|
|
||
| def _chr_check_args(args): | ||
| code_point = args[0] | ||
| return 0 <= code_point <= 0x10ffff | ||
| # args[0] => code_point | ||
| return 0 <= args[0] <= 0x10ffff | ||
|
|
||
|
|
||
| def _complex_check_args(args): | ||
| code_point = args[0] | ||
| return 0 <= code_point <= 0x10ffff | ||
| # args[0] => code_point | ||
| return 0 <= args[0] <= 0x10ffff | ||
|
|
||
|
|
||
| def _divmod_check_args(args): | ||
|
|
@@ -23,32 +23,31 @@ def _divmod_check_args(args): | |
|
|
||
|
|
||
| def _ord_check_args(args): | ||
| string = args[0] | ||
| return (len(string) == 1) | ||
| # param args[0] is a string | ||
| return (len(args[0]) == 1) | ||
|
|
||
|
|
||
| def _bytes_check_args(args): | ||
| arg = args[0] | ||
| if not isinstance(arg, tuple): | ||
| if not isinstance(args[0], tuple): | ||
| return True | ||
| return all(0 <= item <= 255 for item in arg) | ||
| return all(0 <= item <= 255 for item in args[0]) | ||
|
|
||
|
|
||
| def _pow_check_args(config, args): | ||
| num = args[0] | ||
| exp = args[1] | ||
| # num => args[0] | ||
| # exp => args[1] | ||
| if len(args) >= 3: | ||
| mod = args[2] | ||
| # mod => args[2] | ||
| return check_pow(config, args[0], args[1], args[2]) | ||
| else: | ||
| mod = None | ||
| return check_pow(config, num, exp, mod) | ||
| # mod => None | ||
| return check_pow(config, args[0], args[1], None) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines look duplicated. The purpose of the mod variable is to avoid code duplication which is a bad programming practice. Moreover, the new core looks less readable, it's hard to to guess the purpose of each parameter of the check_pow() call. |
||
|
|
||
|
|
||
| def add_pure_builtins(config): | ||
| def add(name, *args, **kw): | ||
| func = getattr(builtins, name) | ||
| pure_func = PureFunction(func, name, *args, **kw) | ||
| config._pure_builtins[name] = pure_func | ||
| config._pure_builtins[name] = PureFunction(func, name, *args, **kw) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to use a temporary variable to make the code more readable. |
||
|
|
||
| ANY_TYPE = None | ||
|
|
||
|
|
@@ -76,6 +75,7 @@ def add(name, *args, **kw): | |
| add('int', 1, FLOAT_TYPES + STR_TYPES, | ||
| # catch ValueError for int('xyz') | ||
| exceptions=ValueError) | ||
|
|
||
| add('len', 1, ITERABLE_TYPES) | ||
| add('list', 1, ITERABLE_TYPES) | ||
| add('oct', 1, int) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import builtins | ||
|
|
||
| from .tools import get_constant_size, ITERABLE_TYPES | ||
|
|
||
| # ISSUE : SystemError: Parent module '' not loaded, cannot perform relative import | ||
| # StackOverFlow search : http://stackoverflow.com/questions/16981921/relative-imports-in-python-3 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you added this comment. Your probably misused Python. Maybe you tried to import a module whereas you were on the wrong directory. To be clear: the code works very well. All unit tests pass, so you must not add such comment. |
||
|
|
||
| class Config: | ||
| # FIXME: use dir()? | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the purpose of this change. It makes the code less readable. The fact that you added a comment means that the code is unclear. I consider that if the code is clear enough, it doesn't require a comment.
Your commit message says "Elimination of unused variables", but it's wrong: the variable is used.