`x: float = False` is a valid annotation??? (intermediate) anthony explains

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

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

  • @Ash-qp2yw
    @Ash-qp2yw 4 หลายเดือนก่อน +17

    So much of watching this for me is "That's weird... no, actually, that makes sense unfortunately"

  • @XRay777
    @XRay777 4 หลายเดือนก่อน +6

    I don't know how he does it but Anthony always manages to leave me speachless. Here I am thinking that I know Python quite well yet he always finds something to demo that makes me go O_o

  • @bojandimic3914
    @bojandimic3914 4 หลายเดือนก่อน +7

    Very nice video! False being a float I kinda expected but I honestly didn't know that the NotImplemented class existed.

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

      there's more about NotImplemented linked in the description too if you're further curious

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

      @@anthonywritescode I am sure I will get to it, I am currently at ~200th video of this playlist. It is very fun and informative to watch. :)

  • @jamesarthurkimbell
    @jamesarthurkimbell 4 หลายเดือนก่อน +5

    We must simply respond "fair enough"

  • @Vic-ic7wi
    @Vic-ic7wi 4 หลายเดือนก่อน +8

    NotImplementedType can be found in the types module (!= typing), along with other useful types (NoneType, EllipsisType, etc) :)

  • @cool-jg2050
    @cool-jg2050 4 หลายเดือนก่อน

    I have a question in pycharm I have interpreter 3.10 do I have to check the checkbox code inspections have incompatible with other Python versions then it produces red underlines with like tkinter it says incompatible with Python 2.7 version? Thanks

  • @Spitfire5592
    @Spitfire5592 4 หลายเดือนก่อน +2

    What I wonder is, why have these quirks in the typing system instead of expecting __lt__ to raise NotImplementedError instead?

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

      to support other class instances as a right part of comparison/arithmetic operation that you don't know how to work with but they may know how
      ```python
      >>> 1 + MyNumberClass()
      ```
      without `int` returning `NotImplemented` for `__add__` it won't be possible to use an overload in `MyNumberClass.__radd__` since `NotImplementedError` will be raised (and they can be raised by anything down the road while every function directly controls what it `return`s)

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

      I explained the reason for that at the end! (note that in addition to the reasons I state in the video it's not raising also, it's returning -- exceptions aren't part of the type system)

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

    That's annoying. Is there a way to circumvent that somehow? I guess you could have tests that catch that but testing types in tests is not my favorite thing...

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

      you could maybe do something with NewType though I haven't found a reason that this detail breaks me yet to rationalize the complexity of NewType

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

      you can also use beartype which allows for type algebra and can easily define a float that isn't a int.

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

    if not 0.0:
    print("python is a scripting languagle")

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

    Not implemented seemed kinda normal to me. Isn't not implemented usually a bottom type in other type systems?