Skip to content

Commit c56eaf1

Browse files
committed
Julia 0.4 compat: AbstractString
1 parent ca7454c commit c56eaf1

File tree

8 files changed

+64
-64
lines changed

8 files changed

+64
-64
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
julia 0.2-
2-
Compat 0.1
2+
Compat 0.2

src/PyCall.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function pyinitialize(libpy::Ptr{Void})
315315
py_void_p::Function = p::Ptr -> PyObject(ccall(pycobject_new, PyPtr, (Ptr{Void}, Ptr{Void}), p, C_NULL))
316316
end
317317
pyversion::VersionNumber =
318-
VersionNumber(convert((Int,Int,Int,String,Int),
318+
VersionNumber(convert((Int,Int,Int,AbstractString,Int),
319319
pyimport("sys")["version_info"])[1:3]...)
320320
pyhashlong::Bool = pyversion::VersionNumber < v"3.2"
321321
pyunicode_literals::Bool = pyversion::VersionNumber >= v"3.0"
@@ -348,16 +348,16 @@ function pyinitialize(libpy::Ptr{Void})
348348
return
349349
end
350350

351-
pyconfigvar(python::String, var::String) = chomp(readall(`$python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('$var'))"`))
352-
pysys(python::String, var::String) = chomp(readall(`$python -c "import sys; print(sys.$var)"`))
351+
pyconfigvar(python::AbstractString, var::AbstractString) = chomp(readall(`$python -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('$var'))"`))
352+
pysys(python::AbstractString, var::AbstractString) = chomp(readall(`$python -c "import sys; print(sys.$var)"`))
353353
pyconfigvar(python, var, default) = let v = pyconfigvar(python, var)
354354
v == "None" ? default : v
355355
end
356356

357357
const dlext = isdefined(Sys, :dlext) ? Sys.dlext : Sys.shlib_ext
358358
const dlprefix = @windows? "" : "lib"
359359

360-
function dlopen_libpython(python::String)
360+
function dlopen_libpython(python::AbstractString)
361361
# it is ridiculous that it is this hard to find the name of libpython
362362
v = pyconfigvar(python,"VERSION","")
363363
libs = [ dlprefix*"python"*v*"."*dlext, dlprefix*"python."*dlext ]
@@ -417,7 +417,7 @@ function dlopen_libpython(python::String)
417417
end
418418

419419
# Python 3.x uses wchar_t arrays for some string arguments
420-
function wbytestring(s::String)
420+
function wbytestring(s::AbstractString)
421421
if pyversion.major < 3 || sizeof(Cwchar_t) == 1 # ASCII (or UTF8)
422422
bytestring(s)
423423
else # UTF16 or UTF32, presumably
@@ -451,7 +451,7 @@ function wbytestring(s::String)
451451
end
452452

453453
# initialize the Python interpreter (no-op on subsequent calls)
454-
function pyinitialize(python::String)
454+
function pyinitialize(python::AbstractString)
455455
global initialized
456456
if !initialized::Bool
457457
libpy = try
@@ -559,7 +559,7 @@ function pystring(o::PyObject)
559559
return string(o.o)
560560
end
561561
end
562-
return convert(String, PyObject(s))
562+
return convert(AbstractString, PyObject(s))
563563
end
564564
end
565565

@@ -631,7 +631,7 @@ isequal(o1::PyObject, o2::PyObject) = o1 == o2 # Julia 0.2 compatibility
631631
# with the former returning an raw PyObject and the latter giving the PyAny
632632
# conversion.
633633

634-
function getindex(o::PyObject, s::String)
634+
function getindex(o::PyObject, s::AbstractString)
635635
if (o.o == C_NULL)
636636
throw(ArgumentError("ref of NULL PyObject"))
637637
end
@@ -646,7 +646,7 @@ end
646646

647647
getindex(o::PyObject, s::Symbol) = convert(PyAny, getindex(o, string(s)))
648648

649-
function setindex!(o::PyObject, v, s::String)
649+
function setindex!(o::PyObject, v, s::AbstractString)
650650
if (o.o == C_NULL)
651651
throw(ArgumentError("assign of NULL PyObject"))
652652
end
@@ -660,7 +660,7 @@ end
660660

661661
setindex!(o::PyObject, v, s::Symbol) = setindex!(o, v, string(s))
662662

663-
function haskey(o::PyObject, s::String)
663+
function haskey(o::PyObject, s::AbstractString)
664664
if (o.o == C_NULL)
665665
throw(ArgumentError("haskey of NULL PyObject"))
666666
end
@@ -706,7 +706,7 @@ end
706706

707707
function pywrap(o::PyObject, mname::Symbol=:__anon__)
708708
@pyinitialize
709-
members = convert(Vector{(String,PyObject)},
709+
members = convert(Vector{(AbstractString,PyObject)},
710710
pycall(inspect["getmembers"], PyObject, o))
711711
filter!(m -> !(m[1] in reserved), members)
712712
m = Module(mname)
@@ -723,7 +723,7 @@ end
723723

724724
#########################################################################
725725

726-
pyimport(name::String) =
726+
pyimport(name::AbstractString) =
727727
PyObject(@pycheckn ccall((@pysym :PyImport_ImportModule), PyPtr,
728728
(Ptr{Uint8},), bytestring(name)))
729729

@@ -805,7 +805,7 @@ function pycall(o::PyObject, returntype::TypeTuple, args...; kwargs...)
805805
ret = PyObject(@pycheckni ccall((@pysym :PyObject_Call), PyPtr,
806806
(PyPtr,PyPtr,PyPtr), o, arg, C_NULL))
807807
else
808-
kw = PyObject((String=>Any)[string(k) => v for (k, v) in kwargs])
808+
kw = PyObject((AbstractString=>Any)[string(k) => v for (k, v) in kwargs])
809809
ret = PyObject(@pycheckni ccall((@pysym :PyObject_Call), PyPtr,
810810
(PyPtr,PyPtr,PyPtr), o, arg, kw))
811811
end
@@ -859,7 +859,7 @@ for (mime, method) in ((MIME"text/html", "_repr_html_"),
859859
(MIME"image/png", "_repr_png_"),
860860
(MIME"image/svg+xml", "_repr_svg_"),
861861
(MIME"text/latex", "_repr_latex_"))
862-
T = istext(mime()) ? String : Vector{Uint8}
862+
T = istext(mime()) ? AbstractString : Vector{Uint8}
863863
@eval begin
864864
function writemime(io::IO, mime::$mime, o::PyObject)
865865
if o.o != C_NULL && haskey(o, $method)
@@ -881,7 +881,7 @@ const pyeval_fname = bytestring("PyCall.jl") # filename for pyeval
881881

882882
# evaluate a python string, returning PyObject, given a dictionary
883883
# (string/symbol => value) of local variables to use in the expression
884-
function pyeval_(s::String, locals::PyDict)
884+
function pyeval_(s::AbstractString, locals::PyDict)
885885
sb = bytestring(s) # use temp var to prevent gc before we are done with o
886886
sigatomic_begin()
887887
try
@@ -901,8 +901,8 @@ function pyeval_(s::String, locals::PyDict)
901901
end
902902
end
903903

904-
function pyeval(s::String, returntype::TypeTuple=PyAny; kwargs...)
905-
locals = PyDict{String,PyObject}()
904+
function pyeval(s::AbstractString, returntype::TypeTuple=PyAny; kwargs...)
905+
locals = PyDict{AbstractString,PyObject}()
906906
for (k, v) in kwargs
907907
locals[string(k)] = v
908908
end

src/callback.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Define a Python method/function object from f(PyPtr,PyPtr)::PyPtr.
1111
# Requires f to be a top-level function.
12-
function pymethod(f::Function, name::String, flags::Integer)
12+
function pymethod(f::Function, name::AbstractString, flags::Integer)
1313
# Python expects the PyMethodDef structure to be a *constant*,
1414
# so we define an anonymous global to hold it.
1515
def = gensym("PyMethodDef")

src/conversions.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ PyObject(s::UTF8String) =
5757
PyPtr, (Ptr{Uint8}, Int, Ptr{Uint8}),
5858
bytestring(s), sizeof(s), C_NULL))
5959

60-
function PyObject(s::String)
60+
function PyObject(s::AbstractString)
6161
@pyinitialize
6262
if pyunicode_literals::Bool
6363
sb = bytestring(s)
@@ -70,7 +70,7 @@ function PyObject(s::String)
7070
end
7171
end
7272

73-
function convert{T<:String}(::Type{T}, po::PyObject)
73+
function convert{T<:AbstractString}(::Type{T}, po::PyObject)
7474
@pyinitialize
7575
if pyisinstance(po, @pysym :PyUnicode_Type)
7676
convert(T, PyObject(@pycheckni ccall(PyUnicode_AsUTF8String::Ptr{Void},
@@ -84,7 +84,7 @@ end
8484
# TODO: should symbols be converted to a subclass of Python strings/bytes,
8585
# so that PyAny conversion can convert it back to a Julia symbol?
8686
PyObject(s::Symbol) = PyObject(string(s))
87-
convert(::Type{Symbol}, po::PyObject) = symbol(convert(String, po))
87+
convert(::Type{Symbol}, po::PyObject) = symbol(convert(AbstractString, po))
8888

8989
#########################################################################
9090
# ByteArray conversions
@@ -158,7 +158,7 @@ pyptr_query(po::PyObject) = pyisinstance(po, c_void_p_Type::PyObject) || pyisins
158158

159159
# I want to use a union, but this seems to confuse Julia's method
160160
# dispatch for the convert function in some circumstances
161-
# typealias PyAny Union(PyObject, Int, Bool, Float64, Complex128, String, Function, Dict, Tuple, Array)
161+
# typealias PyAny Union(PyObject, Int, Bool, Float64, Complex128, AbstractString, Function, Dict, Tuple, Array)
162162
abstract PyAny
163163

164164
# I originally implemented this via multiple dispatch, with
@@ -168,7 +168,7 @@ pyany_toany(x) = isa(x, Type{PyAny}) ? Any : (isa(x, Tuple) ?
168168
map(pyany_toany, x) : x)
169169

170170
# no-op conversions
171-
for T in (:PyObject, :Int, :Bool, :Float64, :Complex128, :String,
171+
for T in (:PyObject, :Int, :Bool, :Float64, :Complex128, :AbstractString,
172172
:Function, :Dict, :Tuple, :Array)
173173
@eval convert(::Type{PyAny}, x::$T) = x
174174
end
@@ -448,7 +448,7 @@ haskey(d::PyDict, key) = 1 == ccall(d.isdict ? (@pysym :PyDict_Contains)
448448
: (@pysym :PyMapping_HasKey),
449449
Cint, (PyPtr, PyPtr), d, PyObject(key))
450450

451-
pyobject_call(d::PyDict, vec::String) = PyObject(@pycheckni ccall((@pysym :PyObject_CallMethod), PyPtr, (PyPtr,Ptr{Uint8},Ptr{Uint8}), d, bytestring(vec), C_NULL))
451+
pyobject_call(d::PyDict, vec::AbstractString) = PyObject(@pycheckni ccall((@pysym :PyObject_CallMethod), PyPtr, (PyPtr,Ptr{Uint8},Ptr{Uint8}), d, bytestring(vec), C_NULL))
452452

453453
keys{T}(::Type{T}, d::PyDict) = convert(Vector{T}, d.isdict ? PyObject(@pycheckni ccall((@pysym :PyDict_Keys), PyPtr, (PyPtr,), d)) : pyobject_call(d, "keys"))
454454

@@ -663,7 +663,7 @@ function PyObject(x::Complex{BigFloat})
663663
end
664664

665665
function convert(::Type{BigFloat}, o::PyObject)
666-
BigFloat(convert(String, PyObject(ccall((@pysym :PyObject_Str),
666+
BigFloat(convert(AbstractString, PyObject(ccall((@pysym :PyObject_Str),
667667
PyPtr, (PyPtr,), o))))
668668
end
669669

@@ -688,7 +688,7 @@ function PyObject(i::BigInt)
688688
end
689689

690690
function convert(::Type{BigInt}, o::PyObject)
691-
BigInt(convert(String, PyObject(ccall((@pysym :PyObject_Str),
691+
BigInt(convert(AbstractString, PyObject(ccall((@pysym :PyObject_Str),
692692
PyPtr, (PyPtr,), o))))
693693
end
694694

@@ -712,7 +712,7 @@ pyfloat_query(o::PyObject) = pyisinstance(o, @pysym :PyFloat_Type) ? Float64 : N
712712
pycomplex_query(o::PyObject) =
713713
pyisinstance(o, @pysym :PyComplex_Type) ? Complex128 : None
714714

715-
pystring_query(o::PyObject) = pyisinstance(o, pystring_type::Ptr{Void}) ? String : pyisinstance(o, @pysym :PyUnicode_Type) ? UTF8String : None
715+
pystring_query(o::PyObject) = pyisinstance(o, pystring_type::Ptr{Void}) ? AbstractString : pyisinstance(o, @pysym :PyUnicode_Type) ? UTF8String : None
716716

717717
pyfunction_query(o::PyObject) = pyisinstance(o, @pysym :PyFunction_Type) || pyisinstance(o, BuiltinFunctionType::PyObject) || pyisinstance(o, ufuncType::PyObject) || pyisinstance(o, TypeType::PyObject) || pyisinstance(o, MethodType::PyObject) || pyisinstance(o, MethodWrapperType::PyObject) ? Function : None
718718

@@ -741,7 +741,7 @@ function pysequence_query(o::PyObject)
741741
else
742742
try
743743
otypestr = get(o["__array_interface__"], PyObject, "typestr")
744-
typestr = convert(String, otypestr)
744+
typestr = convert(AbstractString, otypestr)
745745
T = npy_typestrs[typestr[2:end]]
746746
if T == PyPtr
747747
T = PyObject

src/exception.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Wrapper around Python exceptions
33

44
type PyError <: Exception
5-
msg::String # message string from Julia context, or "" if none
5+
msg::AbstractString # message string from Julia context, or "" if none
66

77
# info returned by PyErr_Fetch/PyErr_Normalize
88
T::PyObject
@@ -12,7 +12,7 @@ type PyError <: Exception
1212
# generate a PyError object. Should normally only be called when
1313
# PyErr_Occurred returns non-NULL, and clears the Python error
1414
# indicator. Assumes Python is initialized!
15-
function PyError(msg::String)
15+
function PyError(msg::AbstractString)
1616
exc = Array(PyPtr, 3)
1717
pexc = convert(Uint, pointer(exc))
1818
# equivalent of passing C pointers &exc[1], &exc[2], &exc[3]:
@@ -38,7 +38,7 @@ function show(io::IO, e::PyError)
3838
if e.traceback.o != C_NULL
3939
o = pycall(format_traceback::PyObject, PyObject, e.traceback)
4040
if o.o != C_NULL
41-
for s in PyVector{String}(o)
41+
for s in PyVector{AbstractString}(o)
4242
print(io, s)
4343
end
4444
end
@@ -51,7 +51,7 @@ end
5151
# call to discard Python exceptions
5252
pyerr_clear() = ccall((@pysym :PyErr_Clear), Void, ())
5353

54-
function pyerr_check(msg::String, val::Any)
54+
function pyerr_check(msg::AbstractString, val::Any)
5555
# note: don't call pyinitialize here since we will
5656
# only use this in contexts where initialization was already done
5757
if ccall((@pysym :PyErr_Occurred), PyPtr, ()) != C_NULL
@@ -60,7 +60,7 @@ function pyerr_check(msg::String, val::Any)
6060
val # the val argument is there just to pass through to the return value
6161
end
6262

63-
pyerr_check(msg::String) = pyerr_check(msg, nothing)
63+
pyerr_check(msg::AbstractString) = pyerr_check(msg, nothing)
6464
pyerr_check() = pyerr_check("")
6565

6666
# Macros for common pyerr_check("Foo", ccall((@pysym :Foo), ...)) pattern.
@@ -121,26 +121,26 @@ type PyIOError <: Exception end
121121

122122
function pyexc_initialize()
123123
global pyexc
124-
exc = [Exception => :PyExc_RuntimeError,
125-
ErrorException => :PyExc_RuntimeError,
126-
SystemError => :PyExc_SystemError,
127-
TypeError => :PyExc_TypeError,
128-
ParseError => :PyExc_SyntaxError,
129-
ArgumentError => :PyExc_ValueError,
130-
KeyError => :PyExc_KeyError,
131-
LoadError => :PyExc_ImportError,
132-
MethodError => :PyExc_RuntimeError,
133-
EOFError => :PyExc_EOFError,
134-
BoundsError => :PyExc_IndexError,
135-
DivideError => :PyExc_ZeroDivisionError,
136-
DomainError => :PyExc_RuntimeError,
137-
OverflowError => :PyExc_OverflowError,
138-
InexactError => :PyExc_ArithmeticError,
139-
MemoryError => :PyExc_MemoryError,
140-
StackOverflowError => :PyExc_MemoryError,
141-
UndefRefError => :PyExc_RuntimeError,
142-
InterruptException => :PyExc_KeyboardInterrupt,
143-
PyIOError => :PyExc_IOError]
124+
exc = @compat Dict(Exception => :PyExc_RuntimeError,
125+
ErrorException => :PyExc_RuntimeError,
126+
SystemError => :PyExc_SystemError,
127+
TypeError => :PyExc_TypeError,
128+
ParseError => :PyExc_SyntaxError,
129+
ArgumentError => :PyExc_ValueError,
130+
KeyError => :PyExc_KeyError,
131+
LoadError => :PyExc_ImportError,
132+
MethodError => :PyExc_RuntimeError,
133+
EOFError => :PyExc_EOFError,
134+
BoundsError => :PyExc_IndexError,
135+
DivideError => :PyExc_ZeroDivisionError,
136+
DomainError => :PyExc_RuntimeError,
137+
OverflowError => :PyExc_OverflowError,
138+
InexactError => :PyExc_ArithmeticError,
139+
MemoryError => :PyExc_MemoryError,
140+
StackOverflowError => :PyExc_MemoryError,
141+
UndefRefError => :PyExc_RuntimeError,
142+
InterruptException => :PyExc_KeyboardInterrupt,
143+
PyIOError => :PyExc_IOError)
144144
for (k,v) in exc
145145
p = convert(Ptr{PyPtr}, pysym_e(v))
146146
if p != C_NULL

src/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ end
214214
function jl_IO_writelines(self_::PyPtr, arg_::PyPtr)
215215
try
216216
io = unsafe_pyjlwrap_to_objref(self_)::IO
217-
for s in PyVector{String}(pyincref(arg_))
217+
for s in PyVector{AbstractString}(pyincref(arg_))
218218
write(io, s)
219219
end
220220
ccall((@pysym :Py_IncRef), Void, (PyPtr,), pynothing::PyPtr)

src/numpy.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function npyinitialize()
5858
end
5959

6060
# directory for numpy include files to parse
61-
inc = pycall(pyimport("numpy")["get_include"], String)
61+
inc = pycall(pyimport("numpy")["get_include"], AbstractString)
6262

6363
# Parse __multiarray_api.h to obtain length and meaning of PyArray_API
6464
try
@@ -209,8 +209,8 @@ type PyArray_Info
209209
readonly::Bool
210210

211211
function PyArray_Info(a::PyObject)
212-
ai = PyDict{String,PyObject}(a["__array_interface__"])
213-
typestr = convert(String, ai["typestr"])
212+
ai = PyDict{AbstractString,PyObject}(a["__array_interface__"])
213+
typestr = convert(AbstractString, ai["typestr"])
214214
T = npy_typestrs[typestr[2:end]]
215215
datatuple = convert((Int,Bool), ai["data"])
216216
sz = convert(Vector{Int}, ai["shape"])

0 commit comments

Comments
 (0)