I don't need `__init__.py`? PEP 420 and namespace packages (intermediate) anthony explains

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

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

  • @sparkyb6
    @sparkyb6 2 ปีที่แล้ว +49

    I see what you did here. Very clever. PEP 420 in video #420 on 4/20.

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

    Everytime I watch one of your videos I realize how much I don't know lol.
    Thank you for the amazing videos as always !!

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

    thanks for explaining the namespace packages

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

    Little confused as to the best way add additional behavior (modules) to an existing distribution. Don't use namespace packages and don't use the old method of updating __init__.py because it is slow. So exactly what should be done?

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

      typically you'd do this with a plugin system -- try searching "anthonywritescode plugin system entrypoints" to find my video about that!

  • @Jason-jb1tf
    @Jason-jb1tf 2 ปีที่แล้ว +4

    The old method of explicit namespace might also have returned the module 2, you had that same pkgutil typo in that file so that init code probably didn't run correctly.

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

    Would you have suggestions on how to properly maintain a namespace package?
    Excluding name squatting, mypy,
    Pytest issues, I have an use case where customers would like to install parts of features my library provides independently - I found limited info on the maintenance aspect as you pointed out

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

      imo a namespace package is just always a bad idea -- you're better to use a plugin system -- here's an example of how to set one up: th-cam.com/video/fY3Y_xPKWNA/w-d-xo.html

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

    with PEP 420, could you potentially override library behavior by namespacing within your own package to another library's namespace or even standard namespace, like if you just plop down an `os` file in your root (or even an `os` directory) could you override existing behavior from an existing namespace just for your code? I suppose that would've potentially always been possible?

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

      it's possible to _add_ modules, but not really override them (though you can "override" modules by putting files earlier in sys.path)

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

    I've watched this video 9 times already. I don't know why, but I keep forgetting #420.

  • @shigengyu
    @shigengyu ปีที่แล้ว

    Thanks! Clear explination and solved my problem.

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

    What exactly is the difference between a "normal" package and a namespace package?

  • @stevehageman6785
    @stevehageman6785 ปีที่แล้ว

    Thanks.

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

    Nice vid!

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

    Nice