On 2022-10-30 11:26:56 +0100, Peter J. Holzer wrote: > On 2022-10-29 23:59:44 +0100, Paulo da Silva wrote: > > The funny thing is that if I replace foos by Foos it works because it gets > > known by the initial initialization :-) ! > > > > ________________________ > > from typing import List, Optional > > > > class GLOBALS: > > Foos: Optional[Foos]=None > [...] > > class Foos: > > That seems like a bug to me.
But is it even true? I just tried to reproduce it (should have done that before answering) with mypy 0.942 (included in Ubuntu 22.04 LTS): ----[p1]--------------------------------------------------------------- from typing import List, Optional class GLOBALS: foos: Optional[Foos]=None class Foo: def __init__(self): pass class Foos: Foos: List[Foo]=[] # SOME GLOBALS ARE USED HERE def __init__(self): pass GLOBALS.foos=Foos() ----------------------------------------------------------------------- ----[p2]--------------------------------------------------------------- from typing import List, Optional class GLOBALS: Foos: Optional[Foos]=None class Foo: def __init__(self): pass class Foos: Foos: List[Foo]=[] # SOME GLOBALS ARE USED HERE def __init__(self): pass GLOBALS.Foos=Foos() ----------------------------------------------------------------------- --- p1 2022-10-31 21:59:49.639869922 +0100 +++ p2 2022-10-31 21:58:19.815830677 +0100 @@ -1,7 +1,7 @@ from typing import List, Optional class GLOBALS: - foos: Optional[Foos]=None + Foos: Optional[Foos]=None class Foo: @@ -15,4 +15,4 @@ def __init__(self): pass -GLOBALS.foos=Foos() +GLOBALS.Foos=Foos() So the only difference is the capitalization of foos. And mypy accepts both (as it probably should): % mypy p1 Success: no issues found in 1 source file % mypy p2 Success: no issues found in 1 source file If you did something different, please explain what you did. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | h...@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
Description: PGP signature
-- https://mail.python.org/mailman/listinfo/python-list