[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-10-01 Thread Michael Smith


Michael Smith  added the comment:

OK, I appreciate the response. The MappingProxy objects I am working with are 
in a nested data structure, so accessing them to coerce them directly isn't 
feasible. I created 

class MappingProxyEncoder(JSONEncoder):
  def default(self, obj):
if isinstance(obj, MappingProxyType):
  return obj.copy()
return JSONEncoder.default(self, obj)

and using that works fine for json.dumps (passes all my tests, at least). But I 
suspect that obj.copy() is more expensive than the code I'm replacing, which is 
a local implementation of ImmutableDict I was trying to do away with, following 
a readthrough of PEP 416. I wonder if there's a cheaper way to get at the 
underlying dictionary.

I suspect I'm not the only python user who foolishly expected MappingProxy to 
be a drop-in replacement for local ImmutableDict implementations. Maybe this 
ticket will be useful for others to read.

--

___
Python tracker 
<https://bugs.python.org/issue34858>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34858] MappingProxy objects should JSON serialize just like a dictionary

2018-09-30 Thread Michael Smith


New submission from Michael Smith :

If a mappingproxy object is a read-only proxy to a mapping, would it make sense 
for them to JSON serialize just like the mapping they come from? Currently, 
json.dumps throws the "I don't know how to serialize this" error:

$ python -c 'import json
> import types
> json.dumps(types.MappingProxyType({}))'
Traceback (most recent call last):
  File "", line 3, in 
  File "/usr/lib64/python3.6/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
  File "/usr/lib64/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib64/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
  File "/usr/lib64/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'mappingproxy' is not JSON serializable

--
components: Library (Lib)
messages: 326756
nosy: Michael Smith2
priority: normal
severity: normal
status: open
title: MappingProxy objects should JSON serialize just like a dictionary
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue34858>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27617] Compiled bdist_wininst missing from embedded distribution

2016-07-26 Thread Michael Smith

Michael Smith added the comment:

Thanks so much Steve I got it working right away!

I peeked into the bdist_wininst.py and saw that it also depended on some local 
exe files.  Copied both of those to the embedded and everything worked like a 
charm.  I did read the documentation previously so I thought the only real 
dependency was the C Runtime.  Working on a network without any net access I 
have to bring in libraries we version, so basically what you describe 
"vendoring".

If you have time to answer I would like to understand why this particular item 
is not part of the embedded.  Or why is it in the regular install by default?  
When I look at the distutils documentation there is very little information 
about this file.  Is this particular item a 3rd party not core python or?  In 
any case thanks for the help again.

--

___
Python tracker 
<http://bugs.python.org/issue27617>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27617] Compiled bdist_wininst missing from embedded distribution

2016-07-25 Thread Michael Smith

New submission from Michael Smith:

It seems that the embedded distribution is missing bdist_wininst.pyc from the 
python35.zip .  If you go to distutils\command, you'll notice only 23 compiled 
python files, where in the regular web based installer for the same Python 
version there are 24 python files in similar relevant folder.  I encountered 
this while trying to install a library into the python runtime that had this 
import statement:

import distutils.command.bdist_wininst

--
components: Distutils
messages: 271301
nosy: denimpowell, dstufft, eric.araujo
priority: normal
severity: normal
status: open
title: Compiled bdist_wininst missing from embedded distribution
type: compile error
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue27617>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24113] shlex constructor unreachable code

2015-05-02 Thread Michael Smith

Michael Smith added the comment:

Hat tip abarnert on StackOverflow for digging in.

http://stackoverflow.com/questions/29996208/putting-shlex-in-debug-mode

This code was introduced in https://hg.python.org/cpython/rev/81a121d21340

--

___
Python tracker 
<http://bugs.python.org/issue24113>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24113] shlex constructor unreachable code

2015-05-02 Thread Michael Smith

New submission from Michael Smith:

In its __init__ method, shlex.shlex sets self.debug = 0. An `if self.debug:` 
statement follows shortly thereafter and without allowing the user to change 
self.debug.

The code inside the if statement is unreachable. Users should either be 
permitted to set debug on via an optional __init__ parameter, or debug should 
be taken out of the initializer altogether.

--
components: Library (Lib)
messages: 242399
nosy: Michael.Smith
priority: normal
severity: normal
status: open
title: shlex constructor unreachable code
type: behavior
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker 
<http://bugs.python.org/issue24113>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19076] Pdb.do_break calls error with obsolete file kwarg

2013-09-22 Thread Michael Smith

New submission from Michael Smith:

Pretty straightforward:

File 
"/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/pdb.py",
 line 675, in do_break
self.error(err, file=self.stdout)
TypeError: error() got an unexpected keyword argument 'file'

Sure enough, line 675 reads:
self.error(err, file=self.stdout)

but line 448:
def error(self, msg):

--
components: Extension Modules
messages: 198309
nosy: Michael.Smith
priority: normal
severity: normal
status: open
title: Pdb.do_break calls error with obsolete file kwarg
versions: Python 3.3

___
Python tracker 
<http://bugs.python.org/issue19076>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15400] int('12345L', 10) raises ValueError

2012-07-19 Thread Michael Smith

New submission from Michael Smith :

The trailing 'L' in representations of long integers causes the int function to 
raise a ValueError. This is unexpected because it's reasonable to expect that 
`int` should be able to parse a number from any string when that string 
represented as a bare word would be a valid python number. The following all 
raise ValueError:

int(hex(12345L), 16)
int(oct(12345L), 8)

but not

int('12345', 10)
int(hex(12345), 16)
int(oct(12345), 8)
(and not bin() because of http://bugs.python.org/issue3186)

--
components: Interpreter Core
messages: 165862
nosy: Michael.Smith
priority: normal
severity: normal
status: open
title: int('12345L', 10) raises ValueError
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue15400>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7757] sys.path is incorrect when prefix is ""

2010-01-25 Thread Michael Smith

Michael Smith  added the comment:

Yes, that does look related. The fix from Issue1676135 seems to handle 
--prefix="/" properly, and from what I can tell PREFIX does get set to "/".

There is also code in getpath.c to set sys.prefix to "/" if it's "".

The correct prefix for configure is actually "", not "/", to avoid 
double-slashes - but neither one seems to work at the moment.

--

___
Python tracker 
<http://bugs.python.org/issue7757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7757] sys.path is incorrect when prefix is ""

2010-01-22 Thread Michael Smith

New submission from Michael Smith :

I've built Python 2.6.2 with a prefix of "" for an embedded system, so it's 
installed into /bin/python, /lib/python2.6/, etc.

If I run a script with "python /tmp/script.py" or by putting in a #!/bin/python 
and executing it directly, sys.path is missing the leading slashes:

['/tmp', 'lib/python26.zip', 'lib/python2.6/', 'lib/python2.6/plat-linux2', 
'lib/python2.6/lib-tk', 'lib/python2.6/lib-old', 'lib/lib-dynload']

This causes all module imports to fail. I can work around this by making /usr a 
symlink to / and running the script as "/usr/bin/python /tmp/script.py", or by 
setting PYTHONHOME=/ before starting Python.

In Modules/getpath.c, search_for_prefix() calls reduce() on argv0_path at the 
end of a do-while loop, so "/bin" becomes "" and the loop terminates. Then 
there's a call to joinpath(PREFIX, "lib/python2.6"), where PREFIX is "", and 
this fails (no leading slash).

calculate_path() warns:

Could not find platform independent libraries 

and falls back to joinpath(PREFIX, "lib/python2.6") again, which still fails.

I was thinking I could work around it by building with prefix="/" instead of 
"", but the behaviour is the same - I don't know why, yet.

--
components: Interpreter Core
messages: 98152
nosy: msm...@cbnco.com
severity: normal
status: open
title: sys.path is incorrect when prefix is ""
type: behavior
versions: Python 2.6

___
Python tracker 
<http://bugs.python.org/issue7757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7756] Complete your registration to Python tracker -- key rt04e51ru5U1WqGum1kklK4ZYWEe1Mkf

2010-01-22 Thread Michael Smith

New submission from Michael Smith :

Python tracker wrote:
> To complete your registration of the user "msm...@cbnco.com" with
> Python tracker, please do one of the following:
> 
> - send a reply to rep...@bugs.python.org and maintain the subject line as is 
> (the
> reply's additional "Re:" is ok),
> 
> - or visit the following URL:
> 
> http://bugs.python.org/?...@action=confrego&otk=rt04e51ru5U1WqGum1kklK4ZYWEe1Mkf
>

--
messages: 98146
nosy: msm...@cbnco.com
severity: normal
status: open
title: Complete your registration to Python tracker -- key  
rt04e51ru5U1WqGum1kklK4ZYWEe1Mkf

___
Python tracker 
<http://bugs.python.org/issue7756>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com