Topics

IronPython string - or Str? - type

László Frank
 

I am working on an a .Net/C# application that performs reflection-like parsing of python scripts using IronPython internals in order to present auto-completion list in editor.

It is often possible to guess a variable actual type, either from resolving it from scope or a debug frame or parsing PythonAst for a relevant AssignmentExpression,
which is cool, because I am able to present a valid auto-completion member list for these cases.
This works pretty well for most clr types and python types like List, or Dictionary but I have trouble with simple types like int32 or string.
The problem is that these types resolve to clr types and I get members of that particular type which may work but does not really what I want to primarily present as valid completions.

So the question is - focusing on "string" -  what type shall I consider in order to get its members as completions like ".format()", ."find()", ".splitlines", etc... 
I would expect something like IronPython.Runtime.Types.String for instance, but I know this does not exists. So can you please help me what is the most accurate type for string handling ?

Thank you.

Stéphane Lozier
 

Sorry for the late reply. In case you haven't figured it out yet, the Python methods for .NET types are in IronPython.Runtime.Operations.StringOps. They're essentially extension methods of string. Similarly, int methods are in IronPython.Runtime.Operations.Int32Ops.


On Fri, Jan 4, 2019 at 7:37 AM László Frank <laszlo.frank@...> wrote:
I am working on an a .Net/C# application that performs reflection-like parsing of python scripts using IronPython internals in order to present auto-completion list in editor.

It is often possible to guess a variable actual type, either from resolving it from scope or a debug frame or parsing PythonAst for a relevant AssignmentExpression,
which is cool, because I am able to present a valid auto-completion member list for these cases.
This works pretty well for most clr types and python types like List, or Dictionary but I have trouble with simple types like int32 or string.
The problem is that these types resolve to clr types and I get members of that particular type which may work but does not really what I want to primarily present as valid completions.

So the question is - focusing on "string" -  what type shall I consider in order to get its members as completions like ".format()", ."find()", ".splitlines", etc... 
I would expect something like IronPython.Runtime.Types.String for instance, but I know this does not exists. So can you please help me what is the most accurate type for string handling ?

Thank you.

Hailiang Shen
 

Thanks for replying. I was not aware of StringOps and Int32Ops. What is the benefit of using them instead of String and Int in the System namespace?

 

Hailiang

 

From: users@ironpython.groups.io <users@ironpython.groups.io> On Behalf Of Stéphane Lozier
Sent: January 30, 2019 7:21 PM
To: users@ironpython.groups.io
Subject: Re: [ironpython] IronPython string - or Str? - type

 

Sorry for the late reply. In case you haven't figured it out yet, the Python methods for .NET types are in IronPython.Runtime.Operations.StringOps. They're essentially extension methods of string. Similarly, int methods are in IronPython.Runtime.Operations.Int32Ops.

 

On Fri, Jan 4, 2019 at 7:37 AM László Frank <laszlo.frank@...> wrote:

I am working on an a .Net/C# application that performs reflection-like parsing of python scripts using IronPython internals in order to present auto-completion list in editor.

It is often possible to guess a variable actual type, either from resolving it from scope or a debug frame or parsing PythonAst for a relevant AssignmentExpression,
which is cool, because I am able to present a valid auto-completion member list for these cases.
This works pretty well for most clr types and python types like List, or Dictionary but I have trouble with simple types like int32 or string.
The problem is that these types resolve to clr types and I get members of that particular type which may work but does not really what I want to primarily present as valid completions.

So the question is - focusing on "string" -  what type shall I consider in order to get its members as completions like ".format()", ."find()", ".splitlines", etc... 
I would expect something like IronPython.Runtime.Types.String for instance, but I know this does not exists. So can you please help me what is the most accurate type for string handling ?

Thank you.

László Frank
 

Thank you Stephane, this information was very useful as I did not yet have time to figure it out.


On Thu, Jan 31, 2019 at 1:21 AM Stéphane Lozier <stephane.lozier@...> wrote:
Sorry for the late reply. In case you haven't figured it out yet, the Python methods for .NET types are in IronPython.Runtime.Operations.StringOps. They're essentially extension methods of string. Similarly, int methods are in IronPython.Runtime.Operations.Int32Ops.

On Fri, Jan 4, 2019 at 7:37 AM László Frank <laszlo.frank@...> wrote:
I am working on an a .Net/C# application that performs reflection-like parsing of python scripts using IronPython internals in order to present auto-completion list in editor.

It is often possible to guess a variable actual type, either from resolving it from scope or a debug frame or parsing PythonAst for a relevant AssignmentExpression,
which is cool, because I am able to present a valid auto-completion member list for these cases.
This works pretty well for most clr types and python types like List, or Dictionary but I have trouble with simple types like int32 or string.
The problem is that these types resolve to clr types and I get members of that particular type which may work but does not really what I want to primarily present as valid completions.

So the question is - focusing on "string" -  what type shall I consider in order to get its members as completions like ".format()", ."find()", ".splitlines", etc... 
I would expect something like IronPython.Runtime.Types.String for instance, but I know this does not exists. So can you please help me what is the most accurate type for string handling ?

Thank you.

Alex Earl
 

They are not new types, they just implement the Python API on top of the .NET System.String and System.Int32. There are also ops for other .NET types that add Python APIs on top of the .NET types. The Str type in IronPython IS the System.String type from .NET. 


On Thu, Jan 31, 2019 at 6:26 AM Hailiang Shen via Groups.Io <hailiang=chiwater.com@groups.io> wrote:

Thanks for replying. I was not aware of StringOps and Int32Ops. What is the benefit of using them instead of String and Int in the System namespace?

 

Hailiang

 

From: users@ironpython.groups.io <users@ironpython.groups.io> On Behalf Of Stéphane Lozier
Sent: January 30, 2019 7:21 PM
To: users@ironpython.groups.io
Subject: Re: [ironpython] IronPython string - or Str? - type

 

Sorry for the late reply. In case you haven't figured it out yet, the Python methods for .NET types are in IronPython.Runtime.Operations.StringOps. They're essentially extension methods of string. Similarly, int methods are in IronPython.Runtime.Operations.Int32Ops.

 

On Fri, Jan 4, 2019 at 7:37 AM László Frank <laszlo.frank@...> wrote:

I am working on an a .Net/C# application that performs reflection-like parsing of python scripts using IronPython internals in order to present auto-completion list in editor.

It is often possible to guess a variable actual type, either from resolving it from scope or a debug frame or parsing PythonAst for a relevant AssignmentExpression,
which is cool, because I am able to present a valid auto-completion member list for these cases.
This works pretty well for most clr types and python types like List, or Dictionary but I have trouble with simple types like int32 or string.
The problem is that these types resolve to clr types and I get members of that particular type which may work but does not really what I want to primarily present as valid completions.

So the question is - focusing on "string" -  what type shall I consider in order to get its members as completions like ".format()", ."find()", ".splitlines", etc... 
I would expect something like IronPython.Runtime.Types.String for instance, but I know this does not exists. So can you please help me what is the most accurate type for string handling ?

Thank you.