python: Ellipsis (...) and typing (beginner - intermediate) anthony explains

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ม.ค. 2025

ความคิดเห็น • 20

  • @akira_asahi
    @akira_asahi 2 ปีที่แล้ว

    Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.

  • @kenny-kvibe
    @kenny-kvibe 3 ปีที่แล้ว +3

    Good video, but what about some functions that return some type but have the body containing only "..." and no return statement, in example:
    def function(x:int) -> str: ...
    What does this do ? Is it like an abstract function, alike a placeholder for later implementation ?
    How does one debug this to see where it proceeds to ?

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +2

      I believe I covered those in the video but I will reiterate:
      - the function doesn't do anything, just returns None (`...` is an expression statement in that context)
      - that's often used to write type stubs (.pyi, overloads, protocols, etc.)
      - or just to demo things

  • @RuslanSkiraUkraine
    @RuslanSkiraUkraine 3 ปีที่แล้ว +1

    maybe I missed but have you talk about the closures?
    a = []
    b = a
    b.append(a)
    print(b) -> [[...]]

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +1

      that's not a closure, that's a recursive repr (and not part of the syntax)

    • @RuslanSkiraUkraine
      @RuslanSkiraUkraine 3 ปีที่แล้ว

      @@anthonywritescode ops you are right about recursive representation but I thought that it [...] is an ellipsis sign?

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +1

      yes and no, three dots is an ellipsis but reprs are just strings (it's replacing an un-representable portion of the object) and not syntax

    • @RuslanSkiraUkraine
      @RuslanSkiraUkraine 3 ปีที่แล้ว

      @@anthonywritescode so '...' is syntax, not the Ellipsis object?
      type(return me not Ellipsis)

    • @anthonywritescode
      @anthonywritescode  3 ปีที่แล้ว +1

      `...` and `Ellipsis` refer to the same builtin object
      but you can put three dots in a repr and it's entirely separate (as it's just a string)
      ```
      class C:
      def __repr__(self) -> str:
      return 'C(...)'
      ```

  • @KatiEileen1
    @KatiEileen1 4 ปีที่แล้ว +7

    Maybe you should become a teacher, at a college or bootcamp, etc.

  • @ruslanvist9958
    @ruslanvist9958 4 หลายเดือนก่อน

    Like and Thx Bro! But where is source mypy? For what pip install mypy?

    • @anthonywritescode
      @anthonywritescode  4 หลายเดือนก่อน +1

      to find the source I usually search "github python package name" -- or you can look on pypi as they are often listed there as well

  • @tbhndbhc
    @tbhndbhc 4 ปีที่แล้ว +2

    Amazing talk:)

  • @Jakub1989YTb
    @Jakub1989YTb 4 ปีที่แล้ว +4

    I'm curious, .. why don't you have an alias command for: "virtualenv venv, venv/bin/activate, pip install mypy, mypy t.py" yet?
    It would have saved you at least an hour of typing by now. It's almost at every "anthony explains" :-)

    • @anthonywritescode
      @anthonywritescode  4 ปีที่แล้ว +8

      lol, well the problem with aliases is they're super confusing in videos. and I type fast enough that they're not super beneficial to me

  • @ozkaa
    @ozkaa 4 ปีที่แล้ว +1

    thanks for this it was useful

  • @Lukas-zl5zs
    @Lukas-zl5zs 3 ปีที่แล้ว +2

    thank you

  • @MrPardiii
    @MrPardiii 2 ปีที่แล้ว

    Thank you for the video. But why does it say "views..." only on your video. First I thought I was tripping.

    • @anthonywritescode
      @anthonywritescode  2 ปีที่แล้ว +1

      weird, maybe a youtube A/B test? I don't see it myself

  • @Jakub1989YTb
    @Jakub1989YTb 4 ปีที่แล้ว +2

    Cool, gitub profilepic shirt :-) (as of time of this comment :D )