Re: A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-09 Thread אורי via Python-list
Thank you.

Uri.
אורי
u...@speedy.net


On Tue, Jul 9, 2024 at 6:40 PM Barry Scott  wrote:

>
>
> On 9 Jul 2024, at 06:13, ⁨אורי via Python-list⁩ <⁨python-list@python.org⁩>
> wrote:
>
>  I tried to subscribe to Python-ideas
>
>
> These days ideas are discussed on https://discuss.python.org/
> It is rare to see an idea on the mailing list.
>
> Barry
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-09 Thread Barry Scott via Python-list


> On 9 Jul 2024, at 06:13, ⁨אורי via Python-list⁩ <⁨python-list@python.org⁩> 
> wrote:
> 
>  I tried to subscribe to Python-ideas

These days ideas are discussed on https://discuss.python.org/
It is rare to see an idea on the mailing list.

Barry


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


A new feature request - parser add_mutually_exclusive_group - add a default value

2024-07-08 Thread אורי via Python-list
Hi,

Please look at this Stack Overflow post:
https://stackoverflow.com/questions/78722378/parser-add-mutually-exclusive-group-how-can-i-set-a-default-value

1. Is there a way to add a default to parser add_mutually_exclusive_group
groups - a value that will be set by default? In this case I
want test-default-languages=True to be set as a default.

2. I tried to subscribe to Python-ideas python-id...@python.org, but I
can't login to
https://mail.python.org/mailman3/lists/python-ideas.python.org/. Although I
did login to https://mail.python.org/mailman/options/python-list . Do I
have to create a new account?

Thanks,
Uri.
אורי
u...@speedy.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Re: Re: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 19:34, Karsten Hilbert  wrote:
>
> > > As per my recent foray into abusing existence-checking for Singleton 
> > > assurance
> > > along such lines as
> > >
> > > >>> try: self.initialized
> > > >>> except AttributeError: print('first instantiation'); self.initialized 
> > > >>> = True
> > >
> > > and then changing that to
> > >
> > > >>> try: self.initialized:bool
> >
> > But that's not equivalent code.
>
> I learned as much (RHS vs LHS).
>
> But it did not _intuitively_ resonate with the sentiment
> "type annotation does not change the running of code".

Unfortunately, that simply means that your intuition was wrong. It
doesn't change my prior statement.

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


Aw: Re: Re: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Karsten Hilbert via Python-list
> > As per my recent foray into abusing existence-checking for Singleton 
> > assurance
> > along such lines as
> >
> > >>> try: self.initialized
> > >>> except AttributeError: print('first instantiation'); self.initialized = 
> > >>> True
> >
> > and then changing that to
> >
> > >>> try: self.initialized:bool
>
> But that's not equivalent code.

I learned as much (RHS vs LHS).

But it did not _intuitively_ resonate with the sentiment
"type annotation does not change the running of code".

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


Re: Re: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 18:25, Karsten Hilbert  wrote:
>
> > > > Fundamentally no, at least not without some shenanigans. Type hints do
> > > > not affect the regular running of the code,
> > >
> > > Except when they do ;-)
> > >
> > > ... depending on what counts as (valid) code ...
> > >
> > > In Python a distinction can be made between "runnable" and "valid" :-D
> > >
> >
> > Can you give a counter-example?
>
> As per my recent foray into abusing existence-checking for Singleton assurance
> along such lines as
>
> >>> try: self.initialized
> >>> except AttributeError: print('first instantiation'); self.initialized = 
> >>> True
>
> and then changing that to
>
> >>> try: self.initialized:bool

But that's not equivalent code. You might just as well say that the
ellipsis here suddenly changes the code:

self.initialized
self.initialized = ...

These are completely different, and they behave differently. Both are
valid, but they mean different things.

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


Aw: Re: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Karsten Hilbert via Python-list
> > > Fundamentally no, at least not without some shenanigans. Type hints do
> > > not affect the regular running of the code,
> >
> > Except when they do ;-)
> >
> > ... depending on what counts as (valid) code ...
> >
> > In Python a distinction can be made between "runnable" and "valid" :-D
> >
>
> Can you give a counter-example?

As per my recent foray into abusing existence-checking for Singleton assurance
along such lines as

>>> try: self.initialized
>>> except AttributeError: print('first instantiation'); self.initialized = True

and then changing that to

>>> try: self.initialized:bool

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


Re: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 18:04, Karsten Hilbert  wrote:
>
> > > or something like that. Basically, any way to avoid writing `= None` over 
> > > and over again.
> >
> > Fundamentally no, at least not without some shenanigans. Type hints do
> > not affect the regular running of the code,
>
> Except when they do ;-)
>
> ... depending on what counts as (valid) code ...
>
> In Python a distinction can be made between "runnable" and "valid" :-D
>

Can you give a counter-example? I mean, yes, any code can be written
that inspects the annotations at runtime and makes whatever changes it
likes, but that's part of what I described as "shenanigans".

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


Aw: Re: Any possible type alias that can also set a default value for a function arg?

2023-10-19 Thread Karsten Hilbert via Python-list
> > or something like that. Basically, any way to avoid writing `= None` over 
> > and over again.
>
> Fundamentally no, at least not without some shenanigans. Type hints do
> not affect the regular running of the code,

Except when they do ;-)

... depending on what counts as (valid) code ...

In Python a distinction can be made between "runnable" and "valid" :-D

Karsten

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


Re: Any possible type alias that can also set a default value for a function arg?

2023-10-18 Thread Chris Angelico via Python-list
On Thu, 19 Oct 2023 at 10:11, Matthew Carruth via Python-list
 wrote:
>
> We have the `Optional[T]` type as a short-hand for Union[T | None] and 
> telling us that said argument may not be present.
>
> However, I find that a majority of the time, we also want to set a default 
> value of None on the argument so that it can be evaluated without doing a 
> getattr() check first.
>
> iow, a lot of `foo: Optional[str] = None` in method signatures.
>
> I'd love to see a companion to the Optional type, I'll call it Default, so 
> that it can take a default value as a second arg, with a default of that 
> being None.
>
> For example:
>
> foo: Default[str] would be equivalent to foo: Optional[str] = None
> foo: Default[str, "bar"] would be equivalent to foo: Optional[str] = "bar"
>
> or something like that. Basically, any way to avoid writing `= None` over and 
> over again.

Fundamentally no, at least not without some shenanigans. Type hints do
not affect the regular running of the code, so they can't add
defaults. You could do it the other way around and have the default
imply that it is optional, and I believe that used to be the way that
MyPy calculated things, but it was ultimately rejected. (I may have
the details wrong on that though, don't quote me.)

Ahh, but shenanigans? What kind of shenanigans is that? Glad you
asked! So, uhh, you could decorate a function and mess with its
defaults.

>>> from typing import Optional
>>> def spam(n: Optional[int]):
... if n is None: print("Default spamminess")
... else: print("Spam " * n)
...
>>> spam(5)
Spam Spam Spam Spam Spam
>>> spam(None)
Default spamminess
>>> spam()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: spam() missing 1 required positional argument: 'n'
>>> spam.__defaults__ = (None,)
>>> spam()
Default spamminess

So you could design a decorator that goes through all the arguments,
finds the ones that say "Optional", and adds a default of None if one
wasn't specified. Good luck with it though. First, you'll have to deal
with the difficulties of aligning arguments (not insurmountable but a
lot of work; don't forget that there are posonly and kwonly args to
consider). Then, you'll have to deal with the much bigger difficulties
of convincing people that this is a good thing.

BTW, rather than a decorator, you could do this by iterating over
every function in a module or class. That might work out easier. Not
sure.

Just be aware that, while Python provides you with all the tools
necessary to shoot yourself in the foot, that isn't a guarantee that
holes in feet are worthwhile.

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


Any possible type alias that can also set a default value for a function arg?

2023-10-18 Thread Matthew Carruth via Python-list
We have the `Optional[T]` type as a short-hand for Union[T | None] and telling 
us that said argument may not be present.

However, I find that a majority of the time, we also want to set a default 
value of None on the argument so that it can be evaluated without doing a 
getattr() check first.

iow, a lot of `foo: Optional[str] = None` in method signatures.

I'd love to see a companion to the Optional type, I'll call it Default, so that 
it can take a default value as a second arg, with a default of that being None. 

For example:

foo: Default[str] would be equivalent to foo: Optional[str] = None
foo: Default[str, "bar"] would be equivalent to foo: Optional[str] = "bar"

or something like that. Basically, any way to avoid writing `= None` over and 
over again.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-03-05 Thread Stefan Behnel


Change by Stefan Behnel :


--
status: open -> closed

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-03-04 Thread Jacob Walls


Jacob Walls  added the comment:

I agree not a bug. To ignore the document default you can set 
`specified_attributes` on the parser as documented:

https://docs.python.org/3/library/pyexpat.html#xml.parsers.expat.xmlparser.specified_attributes

Also, this was explicitly worked on recently in bpo-42151, so hard to imagine 
reversing course so soon. I suggest the issue be re-closed.

--
nosy: +jacobtylerwalls

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread Stefan Behnel


Stefan Behnel  added the comment:

> IMHO if the developer doesn't manage the XML itself it is VERY unreasonable 
> to use the document value and not the developer one.

I disagree. If the document says "this is the default if no explicit value if 
given", then I consider that just as good as providing a value each time. 
Meaning, the attribute *is* in fact present, just not explicitly spelled out on 
the element.

I would specifically like to avoid adding a new option just to override the way 
the document distributes its attribute value spelling across DTD and document 
structure. In particular, the .get() method is the wrong place to deal with 
this.

You can probably configure the parser to ignore the internal DTD subset, if 
that's what you want.

--

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


padremayi  added the comment:

Now:
def get(self, key, default=None)

Future:
def get(self, key, default=None, double_value=False)

No code break

--

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


Change by padremayi :


--
status: closed -> open

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-23 Thread padremayi


padremayi  added the comment:

IMHO if the developer doesn't manage the XML itself it is VERY unreasonable to 
use the document value and not the developer one. At the moment the developer 
must predict the future changes on XML structure.

For my point of view if an attribute is not present get() must return None (or 
the default value passed by developer) AND the document default adding an 
optional parameter to get() call: if True return 2 values, otherwise return the 
document one (current behaviour).

In this way the old code continue to work

--

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-22 Thread Stefan Behnel


Stefan Behnel  added the comment:

The question here is simply, which is considered more important: the default 
provided by the document, or the default provided by Python. I don't think it's 
a clear choice, but the way it is now does not seem unreasonable. Changing it 
would mean deliberate breakage of existing code that relies on the existing 
behaviour, and I do not see a reason to do that.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-21 Thread Ned Deily


Change by Ned Deily :


--
nosy: +eli.bendersky, scoder

___
Python tracker 

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



[issue46798] xml.etree.ElementTree: get() doesn't return default value, always ATTLIST value

2022-02-19 Thread padremayi


New submission from padremayi :

XML test file:









]>



This is a simple object
2022
Myself




Python code:
import xml.etree.ElementTree


try:
xml_data = xml.etree.ElementTree.iterparse("test.xml", events=("start", 
"end"))

for event, xml_tag in xml_data:
if event == "end" and xml_tag.tag == "object":
object_name = xml_tag.get("name")
object_description = xml_tag.find("description").text
works = xml_tag.get("works", default="foo")

print("works value: " + str(works))

xml_tag.clear()

print("Done!")

except (NameError, xml.etree.ElementTree.ParseError):
print("XML error!")


Output:
works value: yes
Done!


Expected behaviour:
works value: foo
Done!

--
components: XML
messages: 413543
nosy: padremayi
priority: normal
severity: normal
status: open
title: xml.etree.ElementTree: get() doesn't return default value, always 
ATTLIST value
type: behavior
versions: Python 3.8

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
versions: +Python 3.9

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread Andrew Svetlov


Andrew Svetlov  added the comment:


New changeset 923c994400b3f1c67f95d25c703e131890a16912 by Miss Islington (bot) 
in branch '3.10':
bpo-46468: document that "-m http.server" defaults to port 8000 (GH-30776) 
(#30787)
https://github.com/python/cpython/commit/923c994400b3f1c67f95d25c703e131890a16912


--

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread Andrew Svetlov


Andrew Svetlov  added the comment:


New changeset b4088801db4b4f56b177b1c01dd873c7922e6a9f by Miss Islington (bot) 
in branch '3.9':
bpo-46468: document that "-m http.server" defaults to port 8000 (GH-30776) 
(#30786)
https://github.com/python/cpython/commit/b4088801db4b4f56b177b1c01dd873c7922e6a9f


--

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions:  -Python 3.9

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread miss-islington


Change by miss-islington :


--
pull_requests: +28972
pull_request: https://github.com/python/cpython/pull/30787

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +28971
pull_request: https://github.com/python/cpython/pull/30786

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-22 Thread Andrew Svetlov


Andrew Svetlov  added the comment:


New changeset c8a536624e8f5d6612e3c275c5b19592583a8cf8 by Jelle Zijlstra in 
branch 'main':
bpo-46468: document that "-m http.server" defaults to port 8000 (GH-30776)
https://github.com/python/cpython/commit/c8a536624e8f5d6612e3c275c5b19592583a8cf8


--
nosy: +asvetlov

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-21 Thread Jelle Zijlstra


Change by Jelle Zijlstra :


--
keywords: +patch
pull_requests: +28961
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30776

___
Python tracker 

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



[issue46468] http.server documentation missing default value for port

2022-01-21 Thread Jelle Zijlstra


New submission from Jelle Zijlstra :

"python -m http.server" works and listens on port 8000, but the docs suggest 
you always have to pass the port. PR incoming.

--
assignee: Jelle Zijlstra
components: Documentation
messages: 411230
nosy: Jelle Zijlstra
priority: normal
severity: normal
status: open
title: http.server documentation missing default value for port
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-21 Thread maximus733


maximus733 <3ed7qja...@liamekaens.com> added the comment:

Thanks for the clarification.

--

___
Python tracker 

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



[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-21 Thread Eric V. Smith


Eric V. Smith  added the comment:

Also see 
https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-20 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

This seems to be the standard confusion people have with mutable defaults, just 
with namedtuple defaults rather than function defaults.

Similar behavior elsewhere in Python:

>>> def f(x, y=[]):
... y.append(x)
... print(y)
... 
... 
>>> f(1)
[1]
>>> f(2)
[1, 2]
>>> f(15)
[1, 2, 15]

Or even

>>> a = []
>>> b = a
>>> b.append(4)
>>> a
[4]

This happens because the values you provide as defaults are *objects*, not 
*expressions* to be re-evaluated. If you make one of the defaults a list, you 
ask the namedtuple to "give me this particular list every time", and it will 
give you that same list, even if it has been modified.

There is currently no support for "construct a brand new list every time" in 
namedtuples. You could look to the dataclasses module for such a feature, where 
you can specify default_factory=list, and it will make a new list for each 
instance.

https://docs.python.org/3/library/dataclasses.html#dataclasses.field

--
nosy: +Dennis Sweeney

___
Python tracker 

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



[issue46450] namedtuple leaks data between instances when field's default value is empty list

2022-01-20 Thread Curtis M


New submission from Curtis M <3ed7qja...@liamekaens.com>:

Example code to replicate issue on python 3.10.2 is attached.

How to replicate issue:
1. Define a namedtuple where all fields have default values. At least one 
field's default value will be an empty list: []
2. Instantiate 2 instances of the namedtuple.
3. In the first instance, use namedtuple._replace() to add a replacement list 
into a field that defaults to [].
4. Now look at the contents of both namedtuples. *Both* of them are modified, 
even though the code only modified the first object.


***

Output from attached example code:

g.P5 1: myNamedTuple(P1='hello', P2='world', P3=None, P4='', P5=[], P6=[])
h.P5 1: myNamedTuple(P1='good', P2='morning', P3=None, P4='', P5=[], P6=[])
Expected: g.P5: []
Actual:   g.P5: []
Expected: h.P5: []
Actual:   h.P5: []
g.P5 2: myNamedTuple(P1='hello', P2='world', P3=None, P4='', P5=['a', 'b'], 
P6=[])
h.P5 2: myNamedTuple(P1='good', P2='morning', P3=None, P4='', P5=['a', 'b'], 
P6=[])
Expected: g.P5: ['a', 'b']
Actual:   g.P5: ['a', 'b']
Expected: h.P5: []
Actual:   h.P5: ['a', 'b']
g.P5 3: myNamedTuple(P1='hello', P2='world', P3=None, P4='', P5=['a', 'b', 'c', 
'd'], P6=[])
h.P5 3: myNamedTuple(P1='good', P2='morning', P3=None, P4='', P5=['a', 'b', 
'c', 'd'], P6=[])
Expected: g.P5: ['a', 'b', 'c', 'd']
Actual:   g.P5: ['a', 'b', 'c', 'd']
Expected: h.P5: []
Actual:   h.P5: ['a', 'b', 'c', 'd']

--
components: Library (Lib)
files: namedtuple_example.py
messages: 411079
nosy: user027.7
priority: normal
severity: normal
status: open
title: namedtuple leaks data between instances when field's default value is 
empty list
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file50568/namedtuple_example.py

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10, Python 3.11 -Python 3.9

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread miss-islington


miss-islington  added the comment:


New changeset bea3f42bb7c360921f864949ef7472a7ecb02cd3 by Miss Islington (bot) 
in branch '3.10':
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
https://github.com/python/cpython/commit/bea3f42bb7c360921f864949ef7472a7ecb02cd3


--

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread miss-islington


Change by miss-islington :


--
pull_requests: +28672
pull_request: https://github.com/python/cpython/pull/30469

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I would say yes, for consistency. It doesn't have any effects on user code that 
I am aware

--

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

Should we backport this?

On Sat, Jan 8, 2022, 12:05 AM miss-islington  wrote:

>
> miss-islington  added the
> comment:
>
>
> New changeset d382f7ee0b98e4ab6ade9384268f25c06be462ad by Batuhan Taskaya
> in branch 'main':
> bpo-46289: Make conversion of FormattedValue not optional on ASDL
> (GH-30467)
>
> https://github.com/python/cpython/commit/d382f7ee0b98e4ab6ade9384268f25c06be462ad
>
>
> --
> nosy: +miss-islington
>
> ___
> Python tracker 
> 
> ___
>

--
nosy: +Batuhan Taskaya

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread miss-islington


miss-islington  added the comment:


New changeset d382f7ee0b98e4ab6ade9384268f25c06be462ad by Batuhan Taskaya in 
branch 'main':
bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)
https://github.com/python/cpython/commit/d382f7ee0b98e4ab6ade9384268f25c06be462ad


--
nosy: +miss-islington

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
keywords: +patch
pull_requests: +28670
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/30467

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I think A is the best option

--

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Lysandros Nikolaou


Lysandros Nikolaou  added the comment:

I agree that A is probably the way to go.

--

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Batuhan Taskaya


Batuhan Taskaya  added the comment:

ASDL technically allows it to be None though neither compiler nor ast.unparse 
can work with it at this moment. 

> FormattedValue(expr value, int? conversion, expr? format_spec)
https://github.com/python/cpython/blob/b127e70a8a682fe869c22ce04c379bd85a00db67/Parser/Python.asdl#L78

>>> import ast
>>> tree = ast.parse("f'{x + 1}'")
>>> tree.body[0].value.values[0].conversion = None
>>> compile(tree, "", "exec")
Traceback (most recent call last):
  File "", line 1, in 
SystemError: Unrecognized conversion character 0

We can either:
A) change ASDL to reflect it is an integer (since it always has been treated 
that way)
B) Support this on both the compiler as well as in the ast.unparse

I'd say A, since this was always broken. @pablogsal @lys.nikolaou WDYT?

--

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy: +BTaskaya

___
Python tracker 

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



[issue46289] AST: FomattedValue conversion's default value should be -1

2022-01-07 Thread Anh71me


New submission from Anh71me :

An unexpected behavior lookup:

```python
>>> ast.FormattedValue(ast.Str('ss')).conversion
>>> ast.unparse(ast.FormattedValue(ast.Str('ss')))
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.9/ast.py", line 1564, in unparse
return unparser.visit(ast_obj)
  File "/usr/local/lib/python3.9/ast.py", line 801, in visit
self.traverse(node)
  File "/usr/local/lib/python3.9/ast.py", line 795, in traverse
super().visit(node)
  File "/usr/local/lib/python3.9/ast.py", line 407, in visit
return visitor(node)
  File "/usr/local/lib/python3.9/ast.py", line 1153, in visit_FormattedValue
self._fstring_FormattedValue(node, self.buffer_writer)
  File "/usr/local/lib/python3.9/ast.py", line 1178, in _fstring_FormattedValue
conversion = chr(node.conversion)
TypeError: an integer is required (got type NoneType)
>>> ast.unparse(ast.FormattedValue(ast.Str('ss'), -1))
'f"{\'ss\'}"'
```

ast.FormattedValue conversion's default value is expected to be -1 but not None

See: https://docs.python.org/3/library/ast.html#ast.FormattedValue

Other:

If certainly, it's also a bug on typeshed.

--
components: Parser
messages: 409955
nosy: iyume, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: AST: FomattedValue conversion's default value should be -1
type: behavior
versions: Python 3.9

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



[issue44674] dataclasses should allow frozendict default value

2021-12-12 Thread Eric V. Smith


Eric V. Smith  added the comment:

@gianni: can you verify that your use case works in 3.11?

--

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-12-11 Thread Gianni Mariani


Gianni Mariani  added the comment:

Excellent. Thanks!

--

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-12-11 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-12-11 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset e029c53e1a408b89a4e3edf30a9b38b094f9c880 by Eric V. Smith in 
branch 'main':
bpo-44674: Use unhashability as a proxy for mutability for default dataclass 
__init__ arguments. (GH-29867)
https://github.com/python/cpython/commit/e029c53e1a408b89a4e3edf30a9b38b094f9c880


--

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-11-30 Thread Eric V. Smith


Change by Eric V. Smith :


--
keywords: +patch
pull_requests: +28093
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29867

___
Python tracker 

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



[issue45867] kwarg default value expression incorrectly evaluated

2021-11-22 Thread Muhamed Itani


Change by Muhamed Itani :


Removed file: https://bugs.python.org/file50456/mpyFrame.pyw

___
Python tracker 

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



[issue45867] kwarg default value expression incorrectly evaluated

2021-11-22 Thread Muhamed Itani


Change by Muhamed Itani :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue45867] kwarg default value expression incorrectly evaluated

2021-11-22 Thread Muhamed Itani


New submission from Muhamed Itani :

I have an MPYFrame class that inherits from tkinter.Frame. It's init looks like 
this:

from os.path import normcase,normpath
def 
__init__(self,master=None,port=None,baudrate=115200,timeout=1,localFolder=normcase(normpath(os.getcwd(:

The problem is, when I check/access the value of localFolder later in the code 
(even directly as a first statement within __init__), it is obvious that 
os.getcwd() is executing, but normcase and/or normpath are not. The resulting 
path contains capital letters (tested on Windows 11), even though it should 
not. If I run:
localFolder=normcase(normpath(localFolder))

as a first statement after init, then check the value of localFolder (for 
example at a debugging breakpoint), it correctly then contains a normalized 
path in which all letters have been converted to lowercase (but only after the 
statement itself has executed).

--
components: Parser
files: mpyFrame.pyw
messages: 406765
nosy: lys.nikolaou, moefear85, pablogsal
priority: normal
severity: normal
status: open
title: kwarg default value expression incorrectly evaluated
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file50456/mpyFrame.pyw

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



[issue44674] dataclasses should allow frozendict default value

2021-10-03 Thread Eric V. Smith


Change by Eric V. Smith :


--
type: compile error -> behavior

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-10-03 Thread Eric V. Smith


Eric V. Smith  added the comment:

That's a good idea, Raymond.

>>> [x.__hash__ is None for x in (list, dict, set, frozenset)]
[True, True, True, False]

I don't think this change would cause any backward compatibility issues, except 
it would now allow a default of something bad like:

>>> class BadList(list):
...   def __hash__(self): return 0
...
>>> isinstance(BadList(), list), BadList.__hash__ is None
(True, False)

I can't say I care too much about now allowing things that didn't used to be 
allowed, especially if they're poorly designed like BadList.

I'll put together a PR.

--

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-10-03 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

[Eric]
> I agree that there's no good way of telling if an
> arbitrary class is immutable, so I'm not sure we can 
> do anything here.

Consider using non-hashability as a proxy indicator for immutability.

-  isinstance(f.default, (list, dict, set))
+  f.default.__hash__ is None

While this is imperfect, it would be more reliable than what we have now.

--
nosy: +rhettinger

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-17 Thread Antony Lee


Change by Antony Lee :


--
nosy:  -Antony.Lee

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-17 Thread Łukasz Langa

Łukasz Langa  added the comment:

Thanks, Max for pushing this across the finish line! ✨  ✨  

Closing this one. Further improvement of BooleanOptionalAction will be 
discussed in BPO-44587.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-17 Thread miss-islington


miss-islington  added the comment:


New changeset 6f6648e436d02bce0e49ba82f4377c0d2f586f0f by Miss Islington (bot) 
in branch '3.10':
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
https://github.com/python/cpython/commit/6f6648e436d02bce0e49ba82f4377c0d2f586f0f


--

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-17 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 27fd31311097ab7326f084b5e0e5f388f8dc6b13 by Łukasz Langa in 
branch '3.9':
[3.9] bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672) 
(GH-27788)
https://github.com/python/cpython/commit/27fd31311097ab7326f084b5e0e5f388f8dc6b13


--

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-16 Thread Łukasz Langa

Change by Łukasz Langa :


--
pull_requests: +26257
pull_request: https://github.com/python/cpython/pull/27788

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-16 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 7.0 -> 8.0
pull_requests: +26256
pull_request: https://github.com/python/cpython/pull/27787

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-16 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f by Maximilian Hils in 
branch 'main':
bpo-38956: don't print BooleanOptionalAction's default twice (GH-27672)
https://github.com/python/cpython/commit/1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f


--
nosy: +lukasz.langa

___
Python tracker 

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



[issue38956] argparse.BooleanOptionalAction should not add the default value to the help string by default

2021-08-09 Thread Maximilian Hils


Change by Maximilian Hils :


--
nosy: +mhils
nosy_count: 5.0 -> 6.0
pull_requests: +26160
pull_request: https://github.com/python/cpython/pull/27672

___
Python tracker 

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



[issue44761] NewType __module__ attr default value

2021-07-30 Thread Łukasz Langa

Change by Łukasz Langa :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue44761] NewType __module__ attr default value

2021-07-30 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 56122b0bba7a9e2e3ec672a6c22bfdd7ecf08cbe by Miss Islington (bot) 
in branch '3.10':
bpo-44761: Change default value of NewType __module__ attr (GH-27406) (GH-27477)
https://github.com/python/cpython/commit/56122b0bba7a9e2e3ec672a6c22bfdd7ecf08cbe


--

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



[issue44761] NewType __module__ attr default value

2021-07-30 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset 7b975f81e4dba70a42c6279539a7fcfe4211b4c0 by Yurii Karabas in 
branch 'main':
bpo-44761: Change default value of NewType __module__ attr (GH-27406)
https://github.com/python/cpython/commit/7b975f81e4dba70a42c6279539a7fcfe4211b4c0


--
nosy: +lukasz.langa

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



[issue44761] NewType __module__ attr default value

2021-07-30 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +25995
pull_request: https://github.com/python/cpython/pull/27477

___
Python tracker 

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



[issue44761] NewType __module__ attr default value

2021-07-28 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
title: NewType __module__ name default value -> NewType __module__ attr default 
value

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



[issue44761] NewType __module__ name default value

2021-07-28 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
keywords: +patch
pull_requests: +25939
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/27406

___
Python tracker 

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



[issue44761] NewType __module__ name default value

2021-07-28 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
title: NewType __module__ name -> NewType __module__ name default value

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



[issue44674] dataclasses should allow frozendict default value

2021-07-24 Thread Gianni Mariani


Gianni Mariani  added the comment:

@Arjun - this is about default values (See the bug description - Using a 
frozendict as a default value)

Try this:

from frozendict import frozendict
from dataclasses import dataclass

@dataclass
class A:
a: frozendict = frozendict(a=1)

This used to work until frozendict became a subclass of dict.

Perhaps another fix is to convert any dict to a frozendict? Maybe not.

How would you handle this case? The only thing I figured was:
from frozendict import frozendict, field
from dataclasses import dataclass

AD=frozendict(a=1)
@dataclass
class A:
a: frozendict = field(default_factory=lambda:AD)

Which imho is cumbersome.

--

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



[issue44674] dataclasses should allow frozendict default value

2021-07-23 Thread Eric V. Smith


Change by Eric V. Smith :


--
assignee:  -> eric.smith

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-07-23 Thread Eric V. Smith


Eric V. Smith  added the comment:

When I originally read this, I read it as frozenset. I agree that there's no 
good way of telling if an arbitrary class is immutable, so I'm not sure we can 
do anything here.

So I think we should close this as a rejected idea.

--

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-07-23 Thread Arjun


Arjun  added the comment:

Which frozendict does your message concern? I found this in some test: 
https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/test/test_builtin.py#L741
 or are you suggesting any user defined immutable object?

I'm not sure indicating that an object should be immutable to dataclasses will 
be less cumbersome than default_factory.

Currently, you have to do this:
> x: frozendict = field(default_factory=frozendict)

But, indicating mutability would be something like this:
> x: frozendict = field(mutable=false)

--
nosy: +CCLDArjun

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-07-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree that would be an improvement.

--
nosy: +eric.smith

___
Python tracker 

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



[issue44674] dataclasses should allow frozendict default value

2021-07-19 Thread Gianni Mariani


New submission from Gianni Mariani :

Using a frozendict as a default value should not cause an error in dataclasses. 
The check for mutability is:

   isinstance(f.default, (list, dict, set))

It appears frozendict has been changed to have a dict base class and it now 
raises an exception.

There should be a way to indicate object mutability as the purpose of the 
isinstance(f.default, (list, dict, set)) check is for mutable default values.

Using default_factory to work around this issue is cumbersome.

--
components: Library (Lib)
messages: 397799
nosy: gianni
priority: normal
severity: normal
status: open
title: dataclasses should allow frozendict default value
type: compile error
versions: Python 3.9

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



[issue44443] dataclass looks up field default value on the class, not the class's __dict__

2021-06-17 Thread Eric V. Smith


Change by Eric V. Smith :


--
title: dataclass looks up default on the class, not the class's __dict__ -> 
dataclass looks up field default value on the class, not the class's __dict__

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



[issue27153] Default value shown by argparse.ArgumentDefaultsHelpFormatter is backwards for action='store_false'

2021-06-03 Thread wim glenn


Change by wim glenn :


--
nosy: +wim.glenn

___
Python tracker 

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



[issue43956] C-API: Incorrect default value for Py_SetProgramName

2021-05-21 Thread Jouke Witteveen


Jouke Witteveen  added the comment:

It is unclear to me what is holding back the proposed pull request. Is it 
simply waiting for someone from docs@python to take a look, or did it fall off 
the radar of vstinner in his related activities to deprecate the legacy API?

--

___
Python tracker 

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



[issue43956] C-API: Incorrect default value for Py_SetProgramName

2021-05-12 Thread STINNER Victor


STINNER Victor  added the comment:

I created bpo-44113: "[C API] Deprecate legacy API for configure Python 
initialization".

--
nosy: +vstinner

___
Python tracker 

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



[issue43956] C-API: Incorrect default value for Py_SetProgramName

2021-04-27 Thread Jouke Witteveen

New submission from Jouke Witteveen :

The default program name is hardcoded in 
Python/initconfig.c:config_init_program_name. It is "python" on Windows, and 
"python3" elsewhere. The documentation currently suggests that it is "python" 
everywhere.

Additionally, the documentation currently says:

> The argument should point to a zero-terminated wide character string in 
> static storage whose contents will not change for the duration of the 
> program’s execution.

The code, however, duplicates the string, so I am not sure this is true.

--
assignee: docs@python
components: Documentation
messages: 392113
nosy: docs@python, joukewitteveen
priority: normal
pull_requests: 24356
severity: normal
status: open
title: C-API: Incorrect default value for Py_SetProgramName
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

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



[issue43203] Default value incorrectly read with unittests on Windows & macOS but not Linux

2021-02-12 Thread Steve Dower


Steve Dower  added the comment:

I'm afraid there's nowhere near enough context in your post for us to look into 
this.

Can you provide some code that you think *should* work but does not? Ideally in 
a post (as in, it should be that short) or as an attachment?

--

___
Python tracker 

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



[issue43203] Default value incorrectly read with unittests on Windows & macOS but not Linux

2021-02-11 Thread Samuel Marks

New submission from Samuel Marks :

Had a couple of commits to try and fix it on GitHub Actions (as I was unable to 
replicate locally), ended up with this very easy fix for Windows:
https://github.com/SamuelMarks/doctrans/commit/98203e9fee3e0a888ab1f4128011dde5fad98f63

To completely remove the default value. The only thing I can assume happened is 
that a different test in the same class—which set the default value to 
something else—changed the default value of the function.

This was all very confusing, and I can only think it to be a bug on python, or 
in GitHub Actions deployment thereof.

PS: The macOS builds are still failing with the previous issue :\

--
components: Windows, macOS
messages: 386845
nosy: ned.deily, paul.moore, ronaldoussoren, samuelmarks, steve.dower, 
tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Default value incorrectly read with unittests on Windows & macOS but not 
Linux
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9

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



[issue42883] __init__ function may incur an incorrect behavior if passing a list as a parameter and set its default value as empty

2021-01-10 Thread Haoyang


Haoyang  added the comment:

Thanks!

--

___
Python tracker 

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



[issue42883] __init__ function may incur an incorrect behavior if passing a list as a parameter and set its default value as empty

2021-01-10 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects

--
nosy: +serhiy.storchaka
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue42883] __init__ function may incur an incorrect behavior if passing a list as a parameter and set its default value as empty

2021-01-10 Thread Haoyang


New submission from Haoyang :

Here is the bug-triggered code snippet in the file uploaded

class A:
def __init__(self, b=[]):
print('b = ', b)
self.a = b 

for i in range(3):
a = A()
a.a.append(1)

print(a.a)

It seems that when I pass a list "b" to __init__ function with default value 
empty list. Every time I create a new instance of this class and append one new 
variable to "self.a", the default value of "b" changed at the next time I 
create another instance of class A.

The outcome of this code snippet is 
a =  []
[1]
a =  [1]
[1, 1]
a =  [1, 1]
[1, 1, 1]

I am new to python. Is it a legal behavior in python? If yes, what is the 
principle beneath it? Thanks in advance!

--
files: test.py
messages: 384765
nosy: haoyang9804
priority: normal
severity: normal
status: open
title: __init__  function may incur an incorrect behavior if passing a list as 
a parameter and set its default value as empty
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file49732/test.py

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2021-01-05 Thread Berker Peksag


Berker Peksag  added the comment:


New changeset 28611c28474a7fafdcf7ea2712f2670dda940eef by Miss Islington (bot) 
in branch '3.8':
bpo-42755: Fix sqlite3.Connection.backup docs (GH-23965)
https://github.com/python/cpython/commit/28611c28474a7fafdcf7ea2712f2670dda940eef


--

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread miss-islington


miss-islington  added the comment:


New changeset 9f6a37cc072dab9f9a13d491d3592d23d9809d2b by Miss Islington (bot) 
in branch '3.9':
bpo-42755: Fix sqlite3.Connection.backup docs (GH-23965)
https://github.com/python/cpython/commit/9f6a37cc072dab9f9a13d491d3592d23d9809d2b


--
nosy: +miss-islington

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
nosy:  -miss-islington
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread miss-islington


Change by miss-islington :


--
pull_requests: +22816
pull_request: https://github.com/python/cpython/pull/23971

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 5.0 -> 6.0
pull_requests: +22815
pull_request: https://github.com/python/cpython/pull/23970

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset abba83b4b91f78dc556dc0b7700ecb46cba22c01 by Erlend Egeberg 
Aasland in branch 'master':
bpo-42755: Fix sqlite3.Connection.backup docs (GH-23965)
https://github.com/python/cpython/commit/abba83b4b91f78dc556dc0b7700ecb46cba22c01


--
nosy: +pablogsal

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread Erlend Egeberg Aasland


Change by Erlend Egeberg Aasland :


--
keywords: +patch
pull_requests: +22810
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23965

___
Python tracker 

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



[issue42755] sqlite3.Connection.backup default value is diffrent between implmentation and docs

2020-12-27 Thread Dong-hee Na


New submission from Dong-hee Na :

Docs says that pages default value is 0 but the implementation is -1

docs: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.backup
impl: 
https://github.com/python/cpython/blob/f4507231e3f0cf8827cec5592571ce371c6813e8/Modules/_sqlite/connection.c#L1565

But the behavior will be the same and if the pages is set to zero, we update 
this value to -1.
https://github.com/python/cpython/blob/f4507231e3f0cf8827cec5592571ce371c6813e8/Modules/_sqlite/connection.c#L1625

So IMHO, I'd like to suggest updating the docs rather than updating the 
implementation.

--
components: Extension Modules
messages: 383838
nosy: berker.peksag, corona10, erlendaasland, serhiy.storchaka
priority: normal
severity: normal
status: open
title: sqlite3.Connection.backup default value is diffrent between 
implmentation and docs

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



[issue42288] typing.get_type_hints() returns Optional[Any] if the default value of the argument is None

2020-11-10 Thread Komiya Takeshi


Komiya Takeshi  added the comment:

Wow, I don't know that behavior. Thank you for your wisdom!

--

___
Python tracker 

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



[issue42288] typing.get_type_hints() returns Optional[Any] if the default value of the argument is None

2020-11-08 Thread Guido van Rossum


Guido van Rossum  added the comment:

There is actually a difference between Any and Optional[Any]. Try the following 
using e.g. mypy:

def f(a: Optional[Any]):
a+1

def g(a: Any):
a+1

You'll get an error in f but not in g.

So this behavior is not a bug.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue42288] typing.get_type_hints() returns Optional[Any] if the default value of the argument is None

2020-11-07 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
components: +Library (Lib)
nosy: +gvanrossum, levkivskyi
type:  -> enhancement
versions:  -Python 3.6, Python 3.7

___
Python tracker 

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



[issue42288] typing.get_type_hints() returns Optional[Any] if the default value of the argument is None

2020-11-07 Thread Komiya Takeshi


New submission from Komiya Takeshi :

I noticed `typing.get_type_hints()` returns Optional[Any] as a type hints if 
the default value of the argument is None:

```
$ python
Python 3.9.0 (default, Oct 24 2020, 15:41:29)
[Clang 11.0.3 (clang-1103.0.32.59)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Any, get_type_hints
>>> def hello(name: Any = None):
... pass
...
>>> get_type_hints(hello)
{'name': typing.Optional[typing.Any]}
```

I know typing.get_type_hints() wraps the user's type annotation with Optional 
when the default value of the argument is None. But it is needless to wrap Any 
with Optional because Any already contains None. It would be better not to wrap 
it with Optional when the user's annotation is Any.

--
messages: 380532
nosy: i.tkomiya
priority: normal
severity: normal
status: open
title: typing.get_type_hints() returns Optional[Any] if the default value of 
the argument is None
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

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



[issue41647] MutableMapping ".setdefault()" to return default value via __getitem__

2020-08-27 Thread Guido van Rossum


Guido van Rossum  added the comment:

I'm with Raymond. Closing.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



  1   2   3   4   5   6   7   >