A typing question

Peter J. Holzer hjp-python at hjp.at
Sun Oct 30 06:14:20 EDT 2022


On 2022-10-29 20:14:12 -0400, Thomas Passin wrote:
> I don't understand
> 
> class Foos:
>      Foos: List[Foo]=[]
> 
> If "Foos" is supposed to be a class attribute, then it cannot have the same
> name as the class.

Why not? They are in different namespaces.

#v+
#!/usr/bin/python3

class Foos:
    Foos = [1, 2, 3]

f = Foos()
print(f.Foos)
#v-

This works and I see no reason why it shouldn't work.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20221030/70497d4c/attachment.sig>


More information about the Python-list mailing list