Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread Paulo da Silva

Às 07:52 de 04/11/22, dn escreveu:

On 04/11/2022 07.50, Chris Angelico wrote:

On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
 wrote:


Às 05:32 de 03/11/22, Paulo da Silva escreveu:

Às 03:24 de 03/11/22, Paulo da Silva escreveu:

Hi!

And a typing problem again!!!
___
class C:
  def __init__(self):
  self.__foos=5*[0]

  @property
  def foos(self) -> list[int]:
  return self.__foos

  @foos.setter
  def foos(self,v: int):
  self.__foos=[v for __i in self.__foos]

c=C()
c.foos=5
print(c.foos)
___

mypy gives the following error:
error: Incompatible types in assignment (expression has type "int",
variable has type "List[int]")

How do I turn around this?


Changing def foos(self) -> list[int]:  to
   def foos(self) -> Union[list[int]]:

I meant, of course,
def foos(self) -> Union[list[int],int]:



Ohhh! I thought this was triggering a strange quirk of the checker in
some way...



Yes, these personal styles (?quirks) are off-putting to others.

Plus "_" means (more or less) "not used anymore"
and for most of us, a weak-identifier name such as "i" is indeed "an 
indexer/counter/... "

Thank you for the suggestions.
BTW, I am not a python pro programmer. I use it as a tool as many other 
tools and some other (few) languages.


..

...and whilst I'm griping,
"To help us to help you please copy-paste the *exact* message"
has been followed by:
"I'm sorry. A bad transposition of the text."

copy-paste for the win!
(and to keep others happy to spend their voluntary time helping you - 
more working-with-the-team thinking to consider - please)
The full original message was there. Seemed to me that that was obvious 
considering the simplicity of the subject and the illustrative toy example.

Anyway, I'm sorry.

Thank you.
Paulo


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


Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-04 Thread dn

On 04/11/2022 07.50, Chris Angelico wrote:

On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
 wrote:


Às 05:32 de 03/11/22, Paulo da Silva escreveu:

Às 03:24 de 03/11/22, Paulo da Silva escreveu:

Hi!

And a typing problem again!!!
___
class C:
  def __init__(self):
  self.__foos=5*[0]

  @property
  def foos(self) -> list[int]:
  return self.__foos

  @foos.setter
  def foos(self,v: int):
  self.__foos=[v for __i in self.__foos]

c=C()
c.foos=5
print(c.foos)
___

mypy gives the following error:
error: Incompatible types in assignment (expression has type "int",
variable has type "List[int]")

How do I turn around this?


Changing def foos(self) -> list[int]:  to
   def foos(self) -> Union[list[int]]:

I meant, of course,
def foos(self) -> Union[list[int],int]:



Ohhh! I thought this was triggering a strange quirk of the checker in
some way...



Yes, these personal styles (?quirks) are off-putting to others.

Plus "_" means (more or less) "not used anymore"
and for most of us, a weak-identifier name such as "i" is indeed "an 
indexer/counter/... "
Accordingly, the question becomes: why not follow the crowd - unless you 
tell me that this is a team/company convention?


...and whilst I'm griping,
"To help us to help you please copy-paste the *exact* message"
has been followed by:
"I'm sorry. A bad transposition of the text."

copy-paste for the win!
(and to keep others happy to spend their voluntary time helping you - 
more working-with-the-team thinking to consider - please)

--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-03 Thread Chris Angelico
On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
 wrote:
>
> Às 05:32 de 03/11/22, Paulo da Silva escreveu:
> > Às 03:24 de 03/11/22, Paulo da Silva escreveu:
> >> Hi!
> >>
> >> And a typing problem again!!!
> >> ___
> >> class C:
> >>  def __init__(self):
> >>  self.__foos=5*[0]
> >>
> >>  @property
> >>  def foos(self) -> list[int]:
> >>  return self.__foos
> >>
> >>  @foos.setter
> >>  def foos(self,v: int):
> >>  self.__foos=[v for __i in self.__foos]
> >>
> >> c=C()
> >> c.foos=5
> >> print(c.foos)
> >> ___
> >>
> >> mypy gives the following error:
> >> error: Incompatible types in assignment (expression has type "int",
> >> variable has type "List[int]")
> >>
> >> How do I turn around this?
> >>
> > Changing def foos(self) -> list[int]:  to
> >   def foos(self) -> Union[list[int]]:
> I meant, of course,
> def foos(self) -> Union[list[int],int]:
>

Ohhh! I thought this was triggering a strange quirk of the checker in
some way...

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


Re: typing: property/setter and lists? [RESOLVED ERRATA]

2022-11-03 Thread Paulo da Silva

Às 05:32 de 03/11/22, Paulo da Silva escreveu:

Às 03:24 de 03/11/22, Paulo da Silva escreveu:

Hi!

And a typing problem again!!!
___
class C:
 def __init__(self):
 self.__foos=5*[0]

 @property
 def foos(self) -> list[int]:
 return self.__foos

 @foos.setter
 def foos(self,v: int):
 self.__foos=[v for __i in self.__foos]

c=C()
c.foos=5
print(c.foos)
___

mypy gives the following error:
error: Incompatible types in assignment (expression has type "int", 
variable has type "List[int]")


How do I turn around this?


Changing def foos(self) -> list[int]:  to
  def foos(self) -> Union[list[int]]:

I meant, of course,
def foos(self) -> Union[list[int],int]:

Sorry.
Paulo


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