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?
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]")
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?
On Fri, 4 Nov 2022 at 05:03, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:I'm sorry. A bad transposition of the text. I meant
Changing def foos(self) -> list[int]: to
def foos(self) -> Union[list[int]]:
fixes the problem.
Not so elegant, however!
Wait, what?!
Union[X, Y] means "X or Y"
Union[X] means "X, but don't complain if it's a @property".
Is that how it goes?
Changing def foos(self) -> list[int]: to
def foos(self) -> Union[list[int]]:
fixes the problem.
Not so elegant, however!
Às 03:24 de 03/11/22, Paulo da Silva escreveu:I meant, of course,
Hi!Changing def foos(self) -> list[int]: to
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?
def foos(self) -> Union[list[int]]:
On 03/11/2022 16.24, Paulo da Silva wrote:
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]")
To help us to help you please copy-paste the *exact* message -
especially which line is in-question.
The above code passes without complaint in PyCharm, and executes.
However, the general rule?convention would be to establish type at the
first mention of the identifier, eg
def __init__(self):
self.__foos:list[int] = 5 * [ 0 ]
# or [ 0, 0, 0, 0, 0, ]
Why the "__i", and not "i", or "_"?Just because of my personal taste.
Às 05:32 de 03/11/22, Paulo da Silva escreveu:
Às 03:24 de 03/11/22, Paulo da Silva escreveu:I meant, of course,
Hi!Changing def foos(self) -> list[int]: to
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?
def foos(self) -> Union[list[int]]:
def foos(self) -> Union[list[int],int]:
On Fri, 4 Nov 2022 at 05:48, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
Às 05:32 de 03/11/22, Paulo da Silva escreveu:
Às 03:24 de 03/11/22, Paulo da Silva escreveu:I meant, of course,
Hi!Changing def foos(self) -> list[int]: to
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?
def foos(self) -> Union[list[int]]:
def foos(self) -> Union[list[int],int]:
Ohhh! I thought this was triggering a strange quirk of the checker in
some way...
On 04/11/2022 07.50, Chris Angelico wrote:
On Fri, 4 Nov 2022 at 05:48, Paulo da Silva
<p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
Às 05:32 de 03/11/22, Paulo da Silva escreveu:
Às 03:24 de 03/11/22, Paulo da Silva escreveu:I meant, of course,
Hi!Changing def foos(self) -> list[int]: to
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?
def foos(self) -> Union[list[int]]:
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.Thank you for the suggestions.
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/... "
...and whilst I'm griping,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.
"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)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 78:25:57 |
Calls: | 6,716 |
Files: | 12,247 |
Messages: | 5,357,829 |