diff --git a/build-android.xml b/build-android.xml
index 027f2dad6c..e3f4c452fb 100644
--- a/build-android.xml
+++ b/build-android.xml
@@ -17,6 +17,14 @@
+
+
+
+
+
+
+
+
args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
- throw new org.python.exceptions.NotImplementedError("bytearray.__format__ has not been implemented.");
- }
@org.python.Method(
__doc__ = ""
diff --git a/python/common/org/python/types/Bytes.java b/python/common/org/python/types/Bytes.java
index e2e3722067..3ef5644b33 100644
--- a/python/common/org/python/types/Bytes.java
+++ b/python/common/org/python/types/Bytes.java
@@ -251,12 +251,6 @@ public org.python.Object __contains__(org.python.Object slice) {
return org.python.types.Bool.FALSE;
}
- @org.python.Method(
- __doc__ = "default object formatter"
- )
- public org.python.types.Str __format__(java.util.List args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
- throw new org.python.exceptions.NotImplementedError("bytes.__format__ has not been implemented.");
- }
@org.python.Method(
__doc__ = "Return self>=value.",
diff --git a/python/common/org/python/types/Complex.java b/python/common/org/python/types/Complex.java
index afda805bad..2680de77a9 100644
--- a/python/common/org/python/types/Complex.java
+++ b/python/common/org/python/types/Complex.java
@@ -161,39 +161,49 @@ private String partToStr(org.python.types.Float x) {
__doc__ = "Return repr(self)."
)
public org.python.Object __repr__() {
- java.lang.StringBuilder buffer = new java.lang.StringBuilder();
- boolean real_present = true;
- if (this.real.value != 0) {
- buffer.append("(");
- if (((org.python.types.Bool) ((this.real).__int__().__eq__(this.real))).value) {
- buffer.append(((org.python.types.Str) this.real.__int__().__repr__()).value);
- } else {
- buffer.append(((org.python.types.Str) this.real.__repr__()).value);
- }
+
+ if (this.real.value != 0.0 || this.real.isNegativeZero()) {
+ return new org.python.types.Str("(" + partToStr(this.real) + ((this.imag.value >= 0.0 && !this.imag.isNegativeZero()) ? "+" : "-") + partToStr(new org.python.types.Float(Math.abs(this.imag.value))) + "j)");
} else {
- real_present = false;
+ return new org.python.types.Str(partToStr(this.imag) + "j");
}
- if (this.real.value != 0 && this.imag.value >= 0) {
+
+ }
+
+
+ @org.python.Method(
+ __doc__ = "complex.__format__() -> str\n\nConvert to a string according to format_spec.",
+ args={"format_spec"}
+ )
+ public org.python.Object __format__(org.python.Object format_spec) {
+ String fs = ((org.python.types.Str) format_spec).value;
+
+
+ if(!(fs.endsWith("f")
+ ||fs.endsWith("F")
+ ||fs.endsWith("g")
+ ||fs.endsWith("G")
+ ||fs.endsWith("e")
+ ||fs.endsWith("E")
+ ||fs.endsWith("n")
+ )){
+ //format specs are ignored by python for complex numbers if no floatingpoit spec is present
+ return this.__repr__();
+ }
+ // use the floating point spec
+
+ java.lang.StringBuilder buffer = new java.lang.StringBuilder();
+
+ buffer.append(((org.python.types.Str) this.real.__format__(format_spec)).value);
+
+ if (this.imag.value >= 0) {
buffer.append("+");
}
- if (((org.python.types.Bool) ((this.imag).__int__().__eq__(this.imag))).value) {
- buffer.append(((org.python.types.Str) (this.imag).__int__().__repr__()).value);
- } else {
- buffer.append(((org.python.types.Str) (this.imag).__repr__()).value);
- }
+ buffer.append(((org.python.types.Str) (this.imag).__format__(format_spec)).value);
buffer.append("j");
- if (real_present) {
- buffer.append(")");
- }
return new org.python.types.Str(buffer.toString());
- }
- @org.python.Method(
- __doc__ = "complex.__format__() -> str\n\nConvert to a string according to format_spec."
- )
- public org.python.Object __format__(org.python.Object format_string) {
- throw new org.python.exceptions.NotImplementedError("complex.__format__ has not been implemented.");
- }
+ }
@org.python.Method(
__doc__ = "Return self= 0.0 && !this.imag.isNegativeZero()) ? "+" : "-") + partToStr(new org.python.types.Float(Math.abs(this.imag.value))) + "j)");
- } else {
- return new org.python.types.Str(partToStr(this.imag) + "j");
- }
- }
@org.python.Method(
__doc__ = "Return self*value.",
diff --git a/python/common/org/python/types/Dict.java b/python/common/org/python/types/Dict.java
index d82ba1d244..0b2037bd73 100644
--- a/python/common/org/python/types/Dict.java
+++ b/python/common/org/python/types/Dict.java
@@ -135,13 +135,6 @@ public org.python.types.Str __repr__() {
return new org.python.types.Str(buffer.toString());
}
- @org.python.Method(
- __doc__ = "default object formatter"
- )
- public org.python.types.Str __format__(org.python.Object other) {
- throw new org.python.exceptions.NotImplementedError("dict.__format__() has not been implemented.");
- }
-
@org.python.Method(
__doc__ = ""
)
diff --git a/python/common/org/python/types/DictKeys.java b/python/common/org/python/types/DictKeys.java
index 08c16200b3..8c41c3e491 100644
--- a/python/common/org/python/types/DictKeys.java
+++ b/python/common/org/python/types/DictKeys.java
@@ -56,12 +56,6 @@ public org.python.types.Str __repr__() {
return new org.python.types.Str(buffer.toString());
}
- @org.python.Method(
- __doc__ = "default object formatter"
- )
- public org.python.types.Str __format__(org.python.Object other) {
- throw new org.python.exceptions.NotImplementedError(this.typeName() + ".__format__() has not been implemented.");
- }
@org.python.Method(
__doc__ = "__dir__() -> list\ndefault dir() implementation"
diff --git a/python/common/org/python/types/DictValues.java b/python/common/org/python/types/DictValues.java
index 86c4da18a9..05cfa681d2 100644
--- a/python/common/org/python/types/DictValues.java
+++ b/python/common/org/python/types/DictValues.java
@@ -47,13 +47,6 @@ public org.python.types.Str __repr__() {
return new org.python.types.Str(buffer.toString());
}
- @org.python.Method(
- __doc__ = "default object formatter"
- )
- public org.python.types.Str __format__(org.python.Object other) {
- throw new org.python.exceptions.NotImplementedError(this.typeName() + ".__format__() has not been implemented.");
- }
-
@org.python.Method(
__doc__ = "__dir__() -> list\ndefault dir() implementation"
)
diff --git a/python/common/org/python/types/Float.java b/python/common/org/python/types/Float.java
index 9f7ee8b3a7..fe2c9cd556 100644
--- a/python/common/org/python/types/Float.java
+++ b/python/common/org/python/types/Float.java
@@ -59,6 +59,41 @@ public Float(org.python.Object[] args, java.util.Map