• is mypy failing here

    From Robin Becker@21:1/5 to All on Thu Nov 24 10:05:03 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Robin Becker on Thu Nov 24 07:34:04 2022
    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Thomas Passin on Thu Nov 24 09:10:28 2022
    On 11/24/2022 7:34 AM, Thomas Passin wrote:
    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)

    Forgot the mypy version:

    C:\Users\tom>mypy --version
    mypy 0.910

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Weatherby,Gerard@21:1/5 to Robin Becker on Thu Nov 24 13:55:41 2022
    https://github.com/python/mypy/issues/12971

    From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Thomas Passin <list1@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$>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kirill Ratkin@21:1/5 to Robin Becker on Thu Nov 24 16:50:04 2022
    Hi Robin,

    mypy --strict gives you detail info.

    On Thu, Nov 24, 2022 at 10:05 +0000, 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
    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robin Becker@21:1/5 to Kirill Ratkin via Python-list on Fri Nov 25 17:12:37 2022
    On 24/11/2022 13:50, Kirill Ratkin via Python-list wrote:
    mypy --strict gives you detail info.
    Thanks Kirill,

    it seems --strict does find the errors. One of those is that on line 9 I have to add a return type ie

    def main() -> None:
    .....

    if that is added then mypy without --strict also finds the real typing error.

    So it seems the tool fails in the simplest cases if you forget some typing.

    Interesting that it works in windows without --strict though.
    --
    Robin Becker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robin Becker@21:1/5 to Thomas Passin on Fri Nov 25 17:00:32 2022
    On 24/11/2022 14:10, Thomas Passin wrote:
    .............

    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)

    Forgot the mypy version:

    C:\Users\tom>mypy --version
    mypy 0.910

    interesting; I'm on archlinux and neither the system python 3.10.8 / mypy 0.982 gives an error. I did try running in my
    self build 3.10.8 with latest mypy 0.991 and mypy 0.910 and I still don't get an error.

    I'll break out the windows 10 laptop and see what happens there.

    You ran with the py runner. I wonder if that does something special.
    --
    Robin Becker

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Robin Becker on Fri Nov 25 13:26:02 2022
    On 11/25/2022 12:00 PM, Robin Becker wrote:
    On 24/11/2022 14:10, Thomas Passin wrote:
    .............

    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)

    Forgot the mypy version:

    C:\Users\tom>mypy --version
    mypy 0.910

    interesting; I'm on archlinux and neither the system python 3.10.8 /
    mypy 0.982 gives an error. I did try running in my self build 3.10.8
    with latest mypy 0.991 and mypy 0.910 and I still don't get an error.

    I'll break out the windows 10 laptop and see what happens there.

    You ran with the py runner. I wonder if that does something special.
    --
    Robin Becker

    I've never noticed any difference running anything else with "py"
    instead of "python3" or whatever would have to be typed to get another
    version.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)