Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Extend Builtin Format function #816

Merged
merged 26 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0de2bc2
work-in-progress: simple tests are passing
staujd02 Jun 6, 2019
212d27a
work-in-progress: working around float formatting
staujd02 Jun 7, 2019
51eb919
work-in-progress: working on padding with characters
staujd02 Jun 7, 2019
1515717
padding left and right work
staujd02 Jun 7, 2019
a57cd72
changed format to a redirect to native types format function
staujd02 Jun 12, 2019
d203fce
removed commented code
staujd02 Jun 12, 2019
6222146
updated to latest version
staujd02 Jun 12, 2019
b2cd878
wip: in a test deadlock
staujd02 Jun 12, 2019
a064f87
green tests: basic format types implemented
staujd02 Jun 12, 2019
d371e13
finished simple passthrough formats
staujd02 Jun 12, 2019
68f6a8c
replace interpolation with concats
Jun 12, 2019
e00cfca
Fixed formatting bugs
Jun 12, 2019
59e5579
fix: last linter checks
Jun 12, 2019
1cfab4f
fix: removed newline, thanks to vim
Jun 12, 2019
5eebdc6
wip: bool formatting
staujd02 Jun 13, 2019
1008ba5
implemented chunck of boolean __format__ function
staujd02 Jun 13, 2019
c58ee3b
brought in lastest changes
staujd02 Jun 13, 2019
0644b2f
clean-up
staujd02 Jun 13, 2019
4fc6e0d
format clean
staujd02 Jun 13, 2019
da8db0e
format clean: new at end of file
staujd02 Jun 13, 2019
eddbdfa
functional: bool formatting
Jun 17, 2019
c872e89
added documentation
Jun 17, 2019
41b4046
merged
Jun 17, 2019
8e2cff7
Merge branch 'master' of https://github.com/beeware/batavia into bett…
Jun 17, 2019
544ca78
fix: formatting
Jun 17, 2019
db81c40
fix: bytes_iter bad to string result
Jun 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion batavia/builtins/format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var exceptions = require('../core').exceptions
var callables = require('../core').callables

function format(args, kwargs) {
if (arguments.length !== 2) {
Expand All @@ -14,14 +15,33 @@ function format(args, kwargs) {
'format() takes at most 2 arguments (' + args.length + ' given)'
)
}
if (args[1] === "" || args[1] === undefined) {
return args[0];
}
if (!args[0].__format__) {
throw new exceptions.BataviaError.$pyclass(
'__format__ not implemented for this type.'
)
}
let stringAutoFormat;
if (stringAutoFormat = stringFormatStandIn(args)) { // See if __format__ is implemented or a stub - TODD: remove
return stringAutoFormat; // If it's a stub, send the formatting to "".format()
}
return args[0].__format__(args[0], args[1]) // TODO: Implement the __format__ function for types like int and string, where it actually can do something
}

function stringFormatStandIn(args) {
const callables = require('../core').callables;
let result = false;
try {
args[0].__format__(args[0], args[1]);
} catch (error) {
if(error.toString() === "TypeError: Cannot read property '$pyclass' of undefined"){
return callables.call_method('{:' + args[1] + '}', 'format', [args[0]], {});
}
}
return result;
}
format.__doc__ = 'Return value.__format__(format_spec)\n\nformat_spec defaults to the empty string'

module.exports = format
module.exports = format;
Loading