home.social

#stdlib — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #stdlib, aggregated by home.social.

fetched live
  1. Now this is an interesting #Python problem. I don't know if it's a #bug, but it's a change in behaviour that I don't see documented.

    I upgraded from #Debian 12/Bookworm to 13/Trixie, so the default Python3 changed from 3.11 to 3.13. A script of mine broke, because `pathlib.Path.is_mount()` changed behaviour when the path is a symlink (at least to a directory).

    i.e. I'm testing a path that is a symlink. The symlink points to a directory. That directory *is* a mountpoint. The `.is_mount()` test in 3.11 returned True, while in 3.13 it returns False.

    This seems wrong to me. Most path-manipulation functions transparently treat symlinks as if they were the pointed-to object unless you pass an option/flag specifically to say you want the symlink itself.

    Gonna have to dig to see what else I can find.

    #pathlib #path #is_mount #stdlib #behaviour #symlink #filesystem #mountpoint #mount

  2. Now this is an interesting #Python problem. I don't know if it's a #bug, but it's a change in behaviour that I don't see documented.

    I upgraded from #Debian 12/Bookworm to 13/Trixie, so the default Python3 changed from 3.11 to 3.13. A script of mine broke, because `pathlib.Path.is_mount()` changed behaviour when the path is a symlink (at least to a directory).

    i.e. I'm testing a path that is a symlink. The symlink points to a directory. That directory *is* a mountpoint. The `.is_mount()` test in 3.11 returned True, while in 3.13 it returns False.

    This seems wrong to me. Most path-manipulation functions transparently treat symlinks as if they were the pointed-to object unless you pass an option/flag specifically to say you want the symlink itself.

    Gonna have to dig to see what else I can find.

    #pathlib #path #is_mount #stdlib #behaviour #symlink #filesystem #mountpoint #mount

  3. Brand new PEP by @emmatyping to add Zstandard to the standard library:
    peps.python.org/pep-0784/

    Will it make it in to 3.14 before the feature freeze on 2025-05-06? It'll be close but it's possible!

    The PEP also suggests namespacing the other compression libraries lzma, bz2 and zlib, with a 10-year deprecation for the old names.

    Join the discussion to give your support, suggestions or feedback:

    discuss.python.org/t/pep-784-a

    #PEP #PEP784 #zstd #zstandard #stdlib #Python #compression

  4. Brand new PEP by @emmatyping to add Zstandard to the standard library:
    peps.python.org/pep-0784/

    Will it make it in to 3.14 before the feature freeze on 2025-05-06? It'll be close but it's possible!

    The PEP also suggests namespacing the other compression libraries lzma, bz2 and zlib, with a 10-year deprecation for the old names.

    Join the discussion to give your support, suggestions or feedback:

    discuss.python.org/t/pep-784-a

    #PEP #PEP784 #zstd #zstandard #stdlib #Python #compression

  5. ePub derived from a specialized Anki deck with integrated Python REPL, focusing on the Python Standard Library. pin.it/6vMDXKvoj via @pinterest

  6. Unix buffering: The clearest explanation I've ever seen about line buffering, block buffering, and tty output vs simple file / pipe
    jvns.ca/blog/2024/11/29/why-pi
    #buffering #stdlib #linux #shell #unix #cli #+

  7. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  8. @astraluma

    It depends on what, exactly, you want. time.localtime() will give you a value in the system's configured #timezone. time.gmtime() will give you #UTC. The difference between those will tell you the current local time's offset from UTC.

    If you want the name of the configured timezone, on many Unix-type systems, you can read /etc/timezone to get it.

    If you want more specific info about a timezone, you can add an external dependency which includes (or provides access to a system-provided) database of timezone info. This stuff changes often, and is decided politically rather than technically, so it's a moving target and the #Python #stdlib doesn't try to include it. `pytz` is one such package with a fairly complete database.

    And you can easily override any of these in a test framework. Using unittest.mock.MagicMock(), for example, lets you override any of the above with whatever value you want those functions to return.

    #pytz #test #mock #MagicMock

  9. @doctorwhom

    Well done, but ...

    >>> import fractions
    >>> fractions.Fraction(0.125)
    Fraction(1, 8)
    >>> fractions.Fraction(0.3333)
    Fraction(6004199023210345, 18014398509481984)
    >>> fractions.Fraction(0.3333).limit_denominator(1000)
    Fraction(1, 3)

    A lesser-known part of the #stdlib

    😂

  10. @doctorwhom

    Well done, but ...

    >>> import fractions
    >>> fractions.Fraction(0.125)
    Fraction(1, 8)
    >>> fractions.Fraction(0.3333)
    Fraction(6004199023210345, 18014398509481984)
    >>> fractions.Fraction(0.3333).limit_denominator(1000)
    Fraction(1, 3)

    A lesser-known part of the #stdlib

    😂

  11. I need a dummy #RubyLang #IMAP server that can support #STARTTLS but otherwise treats most commands as no-ops. I couldn't find anything well-maintained via GitHub or Ruby Toolbox other than the gem from Ruby's #stdlib at:

    ruby-doc.org/3.2.2/gems/net-im

    Rather than gutting Net::IMAP, is there already a gem out there that can be used to support fetch-before-send clients like Apple's Mail that won't send email before completing POP3 or IMAP4 authentication?

  12. Python libs you're using (stdlib and not) that have better alternatives.

    - `dataclasses` -> `attrs`
    - `json` -> `orjson`
    - `requests` -> `httpx`
    - `pyoidc` -> `authlib`
    - `pytest-freezegun` -> `time-machine`
    - `aioredis` -> `redis`

    Have I missed anything?

  13. Python stdlib's `pathlib.Path.with_suffix` is
    utterly broken.

  14. is a universal .

    Cosmopolitan is an optimized C as well as compilation procedure that lets C programs run on , , , , , and even bare with a single executable file. Cosmopolitan uses the Actually Portable Executable format to accomplish this, allowing for all supported platforms to run the code with no system modification.

    Website 🔗️: justine.lol/cosmopolitan/

  15. has someone drunkenly hit C-t again?

    if name.startswith(('assert', 'assret')):
    raise AttributeError("Attributes cannot start with 'assert' or 'assret'")

    github.com/python/cpython/blob
    #python #stdlib #butwhy