https://github.com/python/mypy/issues/12971

From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on 
behalf of Thomas Passin <li...@tompassin.net>
Date: Thursday, November 24, 2022 at 7:36 AM
To: python-list@python.org <python-list@python.org>
Subject: Re: is mypy failing here
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 11/24/2022 5:05 AM, Robin Becker wrote:
> I haven't used dataclasses or typing very much, but while playing about
> I found this didn't give me an expected error
>
> (.py312) robin@minikat:~/devel/reportlab
> $ cat tmp/examples/tdc.py && python tmp/examples/tdc.py && mypy
> tmp/examples/tdc.py
> ##################################
> from dataclasses import dataclass
>
> @dataclass
> class DC:
>      a: str
>      b: str
>
> def main():
>      dc = DC(DC, "B")
>      print(dc)
>
> if __name__ == "__main__":
>      main()
> ##################################
> DC(a=<class '__main__.DC'>, b='B')
> Success: no issues found in 1 source file
> (.py312) robin@minikat:~/devel/reportlab
>
> DC.a is supposed to be a str and I expected mypy to indicate a type error
>
> should typing work for this case?
> --
> Robin Becker


Sounds like a bug.  With Python 3.10:

C:\temp\python>py -V
Python 3.10.4

C:\temp\python>py tdc.py
DC(a=<class '__main__.DC'>, b='B')

C:\temp\python>mypy tdc.py
tdc.py:10: error: Argument 1 to "DC" has incompatible type "Type[DC]";
expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kFNV-Nh17mkih_KN3698Xv9rdmHpmQyEjpm-GBtPKVScpGjUISLM12MJ6yKj4O3JKeNVh7Ft9zhsPV8cURU$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kFNV-Nh17mkih_KN3698Xv9rdmHpmQyEjpm-GBtPKVScpGjUISLM12MJ6yKj4O3JKeNVh7Ft9zhsPV8cURU$>
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to