Re: RegExp - please help me!

2017-12-27 Thread Lele Gaifax
[email protected] writes:

> Please help me with this regexp or tell me that I neeed do this in other way.

I think that using regexps to parse those structures is fragile and difficult
to get right[0], as there are lots of corner cases (comments, complex types,
...).

I'd suggest using a tool designed to do that, for example pycparser[1], that
provides the required infrastructure to parse C units into an AST: from there
you can easily extract interesting pieces and write out in whatever format you
need.

As an example, I used it to extract[2] enums and defines from PostgreSQL C
headers[3] and rewrite them as Python definitions[4].

Good luck,
ciao, lele.

[0] http://regex.info/blog/2006-09-15/247
[1] https://github.com/eliben/pycparser
[2] https://github.com/lelit/pg_query/blob/master/tools/extract_enums.py
[3] 
https://github.com/lfittl/libpg_query/blob/43ce2e8cdf54e4e1e8b0352e37adbd72e568e100/src/postgres/include/nodes/parsenodes.h
[4] https://github.com/lelit/pg_query/blob/master/pg_query/enums/parsenodes.py
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected]  | -- Fortunato Depero, 1929.

-- 
https://mail.python.org/mailman/listinfo/python-list


Default annotations for variables

2017-12-27 Thread Kirill Balunov
Will there be any implications (or is it possible) if all variables will
have an attribute *something like* `__type__` which by default will be
initialized to *something like* `AnyType`. So in the case `x = 12` will be
equivalent to `x: AnyType = 12`.

x: int
x = 12
x.__type__ # int

a, b = 11, 12
a.__type__  # AnyType
b.__type__  # AnyType

And also in this case:

class Dummy:
a: int
b: float
c = []

Dummy.__annotations__  # will be {'a': int, 'b': float, 'c': AnyType}


While I ask purely out of curiosity, I think this is not an off-topic for
python-list.

With kind regards, -gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Default annotations for variables

2017-12-27 Thread Chris Angelico
On Wed, Dec 27, 2017 at 9:41 PM, Kirill Balunov  wrote:
> Will there be any implications (or is it possible) if all variables will
> have an attribute *something like* `__type__` which by default will be
> initialized to *something like* `AnyType`. So in the case `x = 12` will be
> equivalent to `x: AnyType = 12`.
>
> x: int
> x = 12
> x.__type__ # int
>
> a, b = 11, 12
> a.__type__  # AnyType
> b.__type__  # AnyType

This won't work. When you say "a.__type__", it means "take the *value*
referenced by a, and look up its __type__ attribute". So it's
equivalent to writing:

(11).__type__
(12).__type__

To query something about the *variable*, you have to look at its
enclosing namespace. If these are at top level, you'd be looking at
the module-level __annotations__ dictionary. That's also where
x.__type__ would be - it's actually stored in __annotations__["x"].

> And also in this case:
>
> class Dummy:
> a: int
> b: float
> c = []
>
> Dummy.__annotations__  # will be {'a': int, 'b': float, 'c': AnyType}

Now, this situation might be of some interest to the dataclass
discussions. Currently, there's a limitation in that no single source
has information about all three attributes; and that means that the
order ["a", "b", "c"] is actually not stored anywhere. (Annotations
are ordered within themselves; values are ordered within themselves;
but annotations and values are separate.)

There is definitely room to ask the question "can we get default
annotations for any global or class-level name that gets assigned to
without an annotation?". I fully expect that thread to be one of those
gigantic ones, but have fun :)

> While I ask purely out of curiosity, I think this is not an off-topic for
> python-list.

Absolutely, it's not off-topic! Though at some point it might need to
migrate to python-ideas, if there's a proposal to actually change the
language. But there's nothing wrong with asking the question here on
python-list.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Default annotations for variables

2017-12-27 Thread Kirill Balunov
2017-12-27 13:54 GMT+03:00 Chris Angelico :

> This won't work. When you say "a.__type__", it means "take the *value*
> referenced by a, and look up its __type__ attribute". So it's
> equivalent to writing:
>
> (11).__type__
> (12).__type__
>

Thank you for clarification, I understand that names don't have attributes
:). But I did not find the right words to describe the idea.


> To query something about the *variable*, you have to look at its
> enclosing namespace. If these are at top level, you'd be looking at
> the module-level __annotations__ dictionary. That's also where
> x.__type__ would be - it's actually stored in __annotations__["x"].
>

Here I was a bit knocked down by the IPython console. Strangely, but the `
__annotations__` is not initialized to a an empty dict when you start it,
while in Python console it is.


> There is definitely room to ask the question "can we get default
> annotations for any global or class-level name that gets assigned to
> without an annotation?". I fully expect that thread to be one of those
> gigantic ones, but have fun :)
>

Yes this is exactly what I was about to ask :)

With kind regards, -gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Default annotations for variables

2017-12-27 Thread Kirill Balunov
2017-12-27 14:19 GMT+03:00 Kirill Balunov :

> Here I was a bit knocked down by the IPython console. Strangely, but the `
> __annotations__` is not initialized to a an empty dict when you start it,
> while in Python console it is.
>

In addition, there are some imbalance without IPython. Since modules and
classes define namespaces it is strange that:

empty `module` -> has `__annotations__` defined to {}.
empty `class` -> does not have `__annotations__` raises AttributeError.

With kind regards, -gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RegExp - please help me!

2017-12-27 Thread szykcech
> (?s)struct (.+?)\s*\{\s*(.+?)\s*\};

Thank you Vlastimil Brom for regexp and for explanation!
-- 
https://mail.python.org/mailman/listinfo/python-list


PyWin32 installer question

2017-12-27 Thread Skip Montanaro
I'm fiddling around with Appveyor, trying to build a Windows installer
for SpamBayes. This is complicated by two facts:

1. I don't know squat about Windows.

2. I don't have access to a Windows command line.

Consequently, every new attempt requires a change to appveyor.yml and
a git push command. Rather slow going. My latest Appveyor build number
is 59. Most of the changes were simple fixes for syntax errors.

I got to the point where I (finally!) was able to successfully
download the appropriate pywin32 installer, but executing it just
hangs. I sort of assume it's asking os.devnull for something. Alas, I
couldn't find any sort of command line flags for the installer itself
in the pywin32 code. I've tried

pywin32.exe /h

but that just sits there (ignores that flag?) and

pywin32.exe /?

which produced some inscrutable output.

Is there some way to coax it into giving me some help and exiting?

Thanks,

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Default annotations for variables

2017-12-27 Thread INADA Naoki
typing's primary intention is "static" typing with tools like mypy.
Introspection is not primary usage.

Adding such information for every class, module, etc makes
Python slower and fatter.
But I want to make Python more swift and slim.
INADA Naoki  


On Wed, Dec 27, 2017 at 8:39 PM, Kirill Balunov  wrote:
> 2017-12-27 14:19 GMT+03:00 Kirill Balunov :
>
>> Here I was a bit knocked down by the IPython console. Strangely, but the `
>> __annotations__` is not initialized to a an empty dict when you start it,
>> while in Python console it is.
>>
>
> In addition, there are some imbalance without IPython. Since modules and
> classes define namespaces it is strange that:
>
> empty `module` -> has `__annotations__` defined to {}.
> empty `class` -> does not have `__annotations__` raises AttributeError.
>
> With kind regards, -gdg
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] txaws 0.5.0

2017-12-27 Thread Jean-Paul Calderone
Hello all,

I'm pleased to announce the release of txAWS 0.5.0.  txAWS is a library for
interacting with Amazon Web Services (AWS) using Twisted.

You can download the release from PyPI .

Since the last release, the following enhancements have been made:

Features
> 
> - txaws.s3.client.S3Client.get_bucket now accepts a ``prefix`` parameter
> for
>   selecting a subset of S3 objects. (#78)
> - txaws.ec2.client.EC2Client now has a ``get_console_output`` method
> binding
>   the ``GetConsoleOutput`` API. (#82)


Thanks to everyone who contributed and to Least Authority TFA GmbH
 for sponsoring my work on this release.

Jean-Paul
-- 
https://mail.python.org/mailman/listinfo/python-list